0

hello, am new here and new to php/mysql coding.
i have 2 tables - tbl_prodstd and tbl_products
tbl_prodstd - std_id, prod_name, prod_desc, prod_photo, prod_brand
tbl_product - prod_id, std_id, prod_name, prod_brand, prod_desc, prod_price, cat, subcat, prod_photo

i created 3 pages - add_prod.php, addprod.php, func.php

the func.php displays prod_name and prod_brand as selects. selecting prod_name displays the related prod_brand. selecting the prod_brand displays the prod_desc.

when i click the add button in add_prod.php, addprod.php executes.
values are inserted to the tbl_product table. all values are being inserted but i dnt know how to add the std_id, prod_desc and prod_photo in tbl_product table. below are each of the codes

add_prod.php

<?php
session_start();
include('db_connect.php');
include('func.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add product</title>

<link href="CSS/add_prod.css" rel="stylesheet" type="text/css" />

<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="SpryAssets/SpryValidationTextarea.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function() {
    $('#wait_1').hide();
    $('#prod_name').change(function(){
      $('#wait_1').show();
      $('#result_1').hide();
      $.get("func.php", {
        func: "prod_name",
        drop_var: $('#prod_name').val()
      }, function(response){
        $('#result_1').fadeOut();
        setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
      });
        return false;
    });
});

function finishAjax(id, response) {
  $('#wait_1').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}
function finishAjax_tier_three(id, response) {
  $('#wait_2').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}
</script>

<script type="text/javascript">
$(document).ready(function()
{
$(".cat").change(function()
{
var id=$(this).val();
var dataString = 'id='+ id;

$.ajax
({
type: "POST",
url: "ajax.php",
data: dataString,
cache: false,
success: function(html)
{
$(".subcat").html(html);
} 
});

});

});
</script>

<link href="SpryAssets/SpryValidationTextarea.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div id="stylized" class="myform">

<form id="form" name="add_prod" method="post" action="addprod.php" enctype="multipart/form-data">

<h2 align="center"><b>- Add Product -</b></h2>

<h3 align="right"><a href="retailer_home.php"><img src="Images/Main Menu/home_icon.png" width="50" height="50" /></a></h3>

<table width="1000" border="0">
    <tr>
    <td><p align="right">Product Name</p></td>
    <td><!--<span id="sprytextfield2">
      <input type="text" name="prod_name" id="prod_name" />
      <span class="textfieldRequiredMsg">A value is required.</span></span>-->
      <select name="prod_name" id="prod_name" class="prod_name">
      <option value="" selected="selected" disabled="disabled">Select Product Name</option>
      <?php
      getprod_name();
      ?>
      </select>
    </tr>
  <tr>
    <td><p align="right">Product Brand</p></td>
    <td><!--<span id="sprytextfield3">
      <input type="text" name="prod_brand" id="prod_brand" />
      <span class="textfieldRequiredMsg">A value is required.</span></span>
      <select name="prod_brand" class="prod_brand">
      </select>-->
      <span id="wait_1" style="display: none;">
      <img alt="Please Wait" src="Images/ajax-loader.gif"/>
      </span>
      <span id="result_1" style="display: none;"></span>

      </td>
  </tr>
  <tr>
    <td><p align="right">Product Description</p></td>
    <td><!--<span id="sprytextarea1">
    <textarea name="prod_desc" id="prod_desc" cols="45" rows="5"></textarea>
    <span class="textareaRequiredMsg">A value is required.</span><span class="textareaMaxCharsMsg">Exceeded maximum number of characters.</span></span>-->
    <span id="wait_2" style="display: none;">
    <img alt="Please Wait" src="Images/ajax-loader.gif"/>
    </span>
    <span id="result_2" style="display: none;"></span>
    </td>
  </tr>
  <tr>
    <td><p align="right">Product Price (MRU)</p></td>
    <td><span id="sprytextfield4">
    <input type="text" name="prod_price" id="prod_price" />
    <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
  </tr>
  <tr>
    <td><p align="right">Product Category</p></td>
    <td><span id="spryselect1">
      <select name="cat" class="cat">
        <option selected="selected">--Select Category--</option>
        <?php
            include('db_connect.php');
            $sql=mysql_query("select id,cat_name from tblprod_cat ORDER BY id ASC");
            while($row=mysql_fetch_array($sql))
            {
            $id=$row['id'];
            $data=$row['cat_name'];
            echo '<option value="'.$id.'">'.$data.'</option>';
            } 
        ?>
      </select>
      <span class="selectRequiredMsg">Please select an item.</span></span></tr>
  <tr>
    <td><p align="right">Product Subcategory</p></td>
    <td><span id="spryselect2">
      <select name="subcat" class="subcat">
        <option>--Select Subcategory--</option>
      </select>
      <span class="selectRequiredMsg">Please select an item.</span></span></td>
  </tr>
  <tr>
    <td><p align="right">Product Weight/Capacity</p></td>
    <td><span id="sprytextfield5">
      <input type="text" name="prod_w_c" id="prod_w_c" />
      <span class="textfieldRequiredMsg">A value is required.</span></span></td>
  </tr>
 <!-- <tr>
    <td><p align="right">Please choose a file:</p></td>
    <td><input name="uploaded" type="file" /></td>
  </tr>-->
</table>
<p align="center">
  <input type="submit" class="button" name="button" id="button" value="<-- Add product -->"/>
</p>

</form>

</div>
<script type="text/javascript">
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "currency", {validateOn:["blur"]});
var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5", "none", {validateOn:["blur"]});
var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1", {validateOn:["blur"]});
var spryselect2 = new Spry.Widget.ValidationSelect("spryselect2", {validateOn:["blur"]});
</script>
</body>
</html>

addprod.php

<?php

include('db_connect.php');

session_start();

$username = $_SESSION['username'];

$sql=mysql_query("select user_id from tbllogin where username = '$username'");

$prod_name=$_POST['prod_name'];
$prod_brand=$_POST['prod_brand'];
$prod_price=$_POST['prod_price'];
$cat=$_POST['cat'];
$subcat=$_POST['subcat'];
$prod_w_c=$_POST['prod_w_c'];
$url='add_prod.php';


$row=mysql_fetch_array($sql); 

$sql=mysql_query("INSERT INTO tbl_product(user_id, prod_name, prod_brand, prod_price, cat, subcat, prod_w_c) VALUES('$row[user_id]', '$prod_name', '$prod_brand', '$prod_price', '$cat', '$subcat', '$prod_w_c')");

    echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
    echo "<script>alert('This product has been added successfully.')</script>";


?>

func.php

<?php
//**************************************
//     Page load dropdown results     //
//**************************************
function getprod_name()
{
    $result = mysql_query("SELECT DISTINCT prod_name FROM tbl_prodstd") 
    or die(mysql_error());

      while($tier = mysql_fetch_array( $result )) 

        {
           echo '<option value="'.$tier['prod_name'].'">'.$tier['prod_name'].'</option>';
        }

}

//**************************************
//     First selection results     //
//**************************************
if(isset($_GET['func']) && $_GET['func'] == "prod_name") {  
   prod_name($_GET['drop_var']); 
}

function prod_name($drop_var)
{  
    include_once('db_connect.php');
    $result = mysql_query("SELECT * FROM tbl_prodstd WHERE prod_name='$drop_var'") 
    or die(mysql_error());

    echo '<select name="prod_brand" id="prod_brand">
          <option value=" " disabled="disabled" selected="selected">Choose one</option>';

           while($drop_2 = mysql_fetch_array( $result )) 
            {
              echo '<option value="'.$drop_2['prod_brand'].'">'.$drop_2['prod_brand'].'</option>';
            }

    echo '</select> ';
    //echo '<input type="submit" name="submit" value="Submit" />';
    echo "<script type=\"text/javascript\">
$('#wait_2').hide();
    $('#prod_brand').change(function(){
      $('#wait_2').show();
      $('#result_2').hide();
      $.get(\"func.php\", {
        func: \"prod_brand\",
        drop_var: $('#prod_brand').val()
      }, function(response){
        $('#result_2').fadeOut();
        setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400);
      });
        return false;
    });
</script>";
}

//**************************************
//     Second selection results     //
//**************************************
if(isset($_GET['func']) && $_GET['func'] == "prod_brand") {
   drop_2($_GET['drop_var']); 
}

function drop_2($drop_var)
{  
    include_once('db_connect.php');
    $result = mysql_query("SELECT * FROM tbl_prodstd WHERE prod_brand='$drop_var'") 
    or die(mysql_error());

    /*echo '<select name="prod_desc" id="prod_desc">
          <option value=" " disabled="disabled" selected="selected">Choose one</option>';*/

           while($drop_3 = mysql_fetch_array( $result )) 
            {
              /*echo '<option value="'.$drop_3['prod_desc'].'">'.$drop_3['prod_desc'].'</option>';*/
              echo "<textarea>".$drop_3['prod_desc']."</textarea>";
            }

    /*echo '</select> ';*/

}

?>

how can i write the code to add std_id, prod_desc and prod_photo to the tbl_product?

1
Contributor
1
Reply
28
Views
4 Years
Discussion Span
Last Post by sanbhu2105
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.