473,387 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Porblem with SQL statement in my php.

Hello (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.

************************************************** ********************
<?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);
?>
************************************************** *********************
Oct 22 '05 #1
2 1391
>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
Oct 22 '05 #2
Gordon
Your sugestions worked
Thank u
Ian

"Gordon Burditt" <go***********@burditt.org> wrote in message
news:11*************@corp.supernews.com...
I am trying to insert recordes into two tables with the following code. Butfield UserId in table tOrders
and
field OrderID in table tOrderItem
are not updating only the default value 0 is being saved into the records. Ihave 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 SQLstatements.

************************************************* *********************
<?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 hasbeen completed.<br>
Please check that the questions have transfered to your local database fromwithin 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

Oct 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
37
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
28
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
23
by: florian.loitsch | last post by:
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.