Product ID is not being stored in the database
can anyone help? my code doesn't seem to store the value of product开发者_高级运维 id here in my code have a look I am also getting the ID from another table
<?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);
?>
updated the code
$id = $row["ID"]
instead of:
$id = $row;
You have an incorrect array value for $id
instead of the array's ID
key:
$id = $row;
// Should be
$id = $row['ID'];
in your original code there is no error handling,you should do something like this:
$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();
}
And see what error you get.
精彩评论