Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql_query syntax

Status
Not open for further replies.

theoneweasel77

Programmer
Aug 10, 2004
54
US
Can some one tell me what's wrong with the following mysql_query?
Code:
mysql_query("select $move from moves where game_num = '$ID' && color = 'blue'", $db);
The error returned by mysql_error() is
Code:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'from moves where game_num = '1' && color = blue' at line 1
Thanks for your help

Writing code is easy. Getting it to work is a nightmare.
 
what is the value of $move.

Also, if game_num is an INT type in your database then you dont need the single quotes around $ID. I dont know if that would affect whether the mysql accept the query or not... but its worth a try

Westbury

If it aint broke, redesign it!
 
Assign your query to a variable and print it out before doing the mysql_query(). This might give you a hint as to what the problem is.

Also does mysql accept '&&' for 'and'?

Ken
 

No, I don't believe it does.

When you are having trouble with a sql query in php, try running the sql in the mysql interpreter, it will give you more useful error messages.
 
$move could be seen as a variable(maybe empty?).
If this is a column name you may need to change the name for ease of use or start using escape characters.

Echo your query to check what it really reads.

JR
As a wise man once said: To build the house you need the stone.
Back to the Basics!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top