I have done plenty of query's through out my php code but for some reason I can't obtain a certain value from a table.
I am creating orders for dvd's, therefore I am inserting data into the order tables etc. However once my orders have been made I need to update my dvd table with new stock levels.
So I wanted to run a query simply to store the stock level of a certain dvd into a variable. However for some reason, it will not retreive the stock level.
Here is the code I am using:
//Obtain id from previous query
$custid = mysql_insert_id();
echo "Customer id is " . $custid;
$query2 = "INSERT INTO custord (custid, ortime, numdvd, carriage, orvalue)" .
"VALUES ('$custid', now() , '$NoDVD', '$Tx', '$Total')";
if ( !mysql_query($query2,$db) ) {
printError(sprintf("Error %s : %s", mysql_errno(), mysql_error()));
} else {
echo ("Thank you for completing the registration form $Name <br /><br />\n");
}
//Obtain orderid of last entry(the one above)
$orderid = mysql_insert_id();
echo "Order id is " . $orderid;
for($i=0; $i<$NoDVD; $i++){
$query[$i] = "INSERT INTO orderline (orderid, dvdid, qty)" .
"VALUES ('$orderid', '$DVDID[$i]', '1' )";
if ( !mysql_query($query[$i],$db) ) {
printError(sprintf("Error %s : %s", mysql_errno(), mysql_error()));
} else {
echo ("Entered DVD $DVDID[$i] <br /><br />\n");
}
//Here I am trying to retreive the dvd stock level!!!
//$DVDID is set else where, has correct info tho.
//Update DVD Stock Level
$check = "select stock from dvd where dvdid = '$DVDID[$i]'";
$result = mysql_query($check,$db);
$st = $result["stock"];
echo "Current stock level is " . $st;
echo "<br />";
$st = $st - 1;
echo "New Stock level is " . $st;
echo "<br />";
$update = "update dvd Set stock ='$st' where dvdid='$DVDID[$i]'";
if ( !mysql_query($update,$db) ) {
printError(sprintf("Error %s : %s", mysql_errno(), mysql_error()));
} else {
echo ("Updated DVD $DVDID[$i] stock level <br /><br />\n");
}
}
mysql_close($db);
}
exit('</head><body></body></html>');
Seems as though it should work to me.
Thanks for any help
Reg
Gary