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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql_query error

Status
Not open for further replies.

theoneweasel77

Programmer
Aug 10, 2004
54
0
0
US
I can't find a probem in the following mysql_query, though it is working fine. All the variables are set and contain correct data but the table is not being altered.
Code:
mysql_query("UPDATE `moves` SET `$move_from` = '$moves[$foo]', `$move_to` = '$moves[$foo2]' WHERE `ID` = '$ID' && `color` = '$color'", $db);
The column names are actually
Code:
$move_from = "move".$i."from";
$move_to = "move".$i."to";
where $i is an autoincremented number (this is in a for() loop) The only thing I can think of is that you can't use variables to set column names. is this true? is there a way around that? mysql_error() prints nothing.
 
I'm no expert on mysql but you seem to be using ` where its not needed. I dont know if thats the problem.
Try something like
Code:
$query = "UPDATE moves SET $move_from = '$moves[$foo]', $move_to = '$moves[$foo2]' WHERE ID = '$ID' && color = '$color'";
mysql_query($query, $db);

I've never had a problem with using variables for column names.
 
Also make sure that a record definitely exists in the database where ID = $ID and color = $color.

Do a SELECT * FROM moves WHERE id = '$ID' AND color = '$color'

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top