[RESOLVED] whats wrong with my code
Hi all..may i know what is wrong with my codes..
I have 2 tables..company(com_id,com_code,com_name) and purchase(po_id,po_no,com_code).Now i want to insert all values.
There are one drop down combo in my form to display com_name.Now I want to insert value of com_code.Can someone let me know why com_code not saved into my db.
Here is my codes:
In form
PHP Code:
<td><select name="com_name">
<?
$sqlst = mysql_query("SELECT com_name,com_code FROM company ORDER BY com_name");
while($company = mysql_fetch_array($sqlst)){ ?>
<option value="<? echo $company['com_code'] ?>"><? echo $company['com_name'] ?>
</option>
<? } ?>
</select></td>
In Insert Process
PHP Code:
<?
include ("../../odbc.php");
echo $po_no=$_POST['po_no'];
echo $po_date=$_POST['po_date'];
echo $com_name=$_POST['com_name'];
echo $com_code=$_POST['com_code'];
$query_add_data = "INSERT INTO purchase(po_no,po_date,com_code) VALUES ('$po_no','$po_date','$com_code')";
$result=mysql_query($query_add_data) or die("Could Not Add");
echo "<META HTTP-EQUIV=Refresh CONTENT=\"5; URL=add_stockin.php\">";
?>
Thanks in advance
Re: whats wrong with my code
because $_POST['com_code'] isn't defined (as far as I can tell) in your form. the form portion you posted is defining com_name, the value of $_POST['com_name'] will be the $company['com_code'] that was selected. so, just change your INSERT query to add in $com_name instead of $com_code, or change the name of the form element from com_name to com_code.
Re: whats wrong with my code
Quote:
Originally Posted by kows
because $_POST['com_code'] isn't defined (as far as I can tell) in your form. the form portion you posted is defining com_name, the value of $_POST['com_name'] will be the $company['com_code'] that was selected. so, just change your INSERT query to add in $com_name instead of $com_code, or change the name of the form element from com_name to com_code.
Thanks a lot.. :)