[英]Inserting data into one table with two foreign keys
I have two tables (for POS system) named: purchase and product . 我有两个表(用于POS系统),分别为: purchase和product 。 The columns of the purchase table are: poid (PK, auto_increment), prodid (FK), poquantity.
购买表的列是:poid(PK,auto_increment),prodid(FK),数量。 The columns of the product table are: prodid (PK, auto_increment), prodname, price, quantity.
产品表的列是: 产品 (PK,auto_increment),产品名称,价格,数量。 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? 每当我按下“提交”按钮时,它都会说: 身份不明的索引:prodid请提供帮助或建议? I'm still a student learning about PHP.
我还是一个学习PHP的学生。 Thanks!
谢谢! :)
:)
Your form action is addprodcon.php?id=$row[prodid]
. 您的表单操作是
addprodcon.php?id=$row[prodid]
。 It is $_GET['id']
, and not $_GET['prodid']
that you should use on line 4 of addprodcon.php. 您应该在addprodcon.php的第4行上使用的是
$_GET['id']
而不是$_GET['prodid']
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.