|
Posted by Gordon Burditt on 10/23/05 02:00
>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.
The return value of mysql_query() is *NOT* a value of what you
selected. It's a result set. Fetch a row (you might have gotten
more than one row) from the result set (e.g. with $r =
mysql_fetch_array($OrderID).) Then look for the column (e.g.
$r['OrderID'] you asked for, and THAT'S the value you want to put
in the query.
Also, when you're debugging something, don't put @ in front of
function calls. Also, print out the SQL being passed to mysql_query.
You never set $id (unless it's hidden in your includes).
>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.
>
>**********************************************************************
><?php
>
>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());
>
>?>
><h1>Order Status</h1>
><p>Congratulations <b><?php echo $_SESSION[username] ?></b>, your order has
>been completed.<br>
>Please check that the questions have transfered to your local database from
>within Pupil Tester.<br><br><br><br>
><a href=\logout.php\> Logout</a> or return to <a href=\Questions.php\>
>Questions Database</a></p>
>
><?php
>mysql_close($conn);
>?>
>***********************************************************************
Gordon L. Burditt
[Back to original message]
|