Porblem with SQL statement in my php.
am 23.10.2005 00:30:37 von Ian DaviesHello (Again)
I am trying to insert recordes into two tables with the following code. But
field UserId in table tOrders
and
field OrderID in table tOrderItem
are not updating only the default value 0 is being saved into the records. I
have been pondering this one all day. I expect as I am new to php I am
missing something obvious but I cannot see it. All the other fields are
being created OK and the $_SESSION[username] is OK as it can be echoed on
the page. I suspect it must be something to do with the variables in the SQL
statements.
************************************************************ **********
session_start();
include('iddsof2.php');
include("login.php");
$OrderDate = date('d/m/Y');
echo $_SESSION[username];
$UserID = mysql_query("SELECT id FROM users WHERE username
='".$_SESSION[username]."'");
$OrderID = mysql_query("SELECT OrderID FROM tOrders WHERE UserID =
'$UserID'");
$insertOrder = "INSERT INTO tOrders (UserId,OrderDate,OrderCost) VALUES
('$id','$OrderDate',10)";
$add_order = @mysql_query($insertOrder) or die('Query failed: ' .
mysql_error());
$insertOrderDetails = "INSERT INTO tOrderItem (OrderID,QuestionNo) VALUES
('$OrderID',10)";
$add_order_details = @mysql_query($insertOrderDetails) or die('Query failed:
' . mysql_error());
?>
Order Status
Congratulations , your order has
been completed.
Please check that the questions have transfered to your local database from
within Pupil Tester.
or return to
Questions Database
mysql_close($conn);
?>
************************************************************ ***********