I have two tables (for POS system) named: purchase and product. The columns of the purchase table are: poid (PK, auto_increment), prodid (FK), poquantity. The columns of the product table are: prodid (PK, auto_increment), prodname, price, quantity. I want to insert the data into the purchase table.
Here are the form codes:
<?php
$tbl_name="product";
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("pos", $con);
$prodid=$row['prodid'];
$result = mysql_query("SELECT prodname FROM product where prodid = '$prodid'");
echo "<form action='addprodcon.php?id=$row[prodid]' method='POST'>
<input name='add' type='submit' value='ADD'></br></br>
</form>";
?>
Here are the insert codes I have created:
<?php
include('includes/dbcon.php');
$prodid = $_GET['prodid'];
$sql1="SELECT prodid FROM product WHERE prodid='$prodid'";
if(mysql_query($sql1))
{
$sql2="INSERT INTO purchase (`prodid`, `poquantity`)
VALUES
('$prodid','$_POST[poquantity]')";
}
if (mysql_query($sql2))
{
// Success
if ( $poquantity > $_POST['quantity'])
{
echo "You already reached the maximum quantity";
}
}
else
{
die('Error on query 2');
}
?>
Whenever I hit the submit button, it say: Unidentified index: prodid Help or suggestions, please? I'm still a student learning about PHP. Thanks! :)