有人能帮忙吗?我的代码似乎没有存储产品id的值在我的代码来看一下,我还从另一个表
获取id <?php
include("Connection.php");
$dTime = time();
$myValue = $_REQUEST['dValue'];
echo "<p>
The time is: {$dTime}<br/>
The choice is {$myValue}
</p>
";
$sql = "Select ID from product where NAME = '$myValue'";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result))
$pid=$row["PRODUCT_ID"];
$sql2 = "INSERT INTO `starbucks`.`order_details` (
`ID` ,
`ORDER_ID` ,
`PRODUCT_ID` ,
`QTY`
)
VALUES (
NULL , '', '$pid', '1'
)";
$result2 = mysql_query($sql2);
?>
更新了代码
$id = $row["ID"]
代替:
$id = $row;
您的$id
的数组值不正确,而不是数组的ID
键:
$id = $row;
// Should be
$id = $row['ID'];
在你的原始代码中没有错误处理,你应该这样做:
$sql = "Select ID from product where NAME = '$myValue'";
if ($sql) {
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result))
$pid = $row["PRODUCT_ID"];
$sql2 = "INSERT INTO `starbucks`.`order_details` (
`ID` ,
`ORDER_ID` ,
`PRODUCT_ID` ,
`QTY`
)
VALUES (
NULL , '', '$pid', '1'
)";
$result2 = mysql_query($sql2);
if (!$result2) {
echo mysql_error();
break;
}
} else {
echo mysql_error();
}
看看会得到什么错误