Hey. I need some help with getting a record from a mysql database and compare it with data already stored in a php variable. If they don't match then I want to save the record in the database under another field and then update it. Here is my code:

$query = "SELECT * FROM players WHERE UID='$uid';



$row = mysql_fetch_array($result) or die(mysql_error());

mysql_query("UPDATE players SET NickOld = {$row['Nick']} AND Nick = '$nick' WHERE UID = '$uid'");

So what I do is check if $nick is equal to the data stored in the field namned Nick in database. If not I want to save that record to another field namned NickOld and then set the Nick field to the new data. But I get the error "unexpected T_STRING" on this line

mysql_query("UPDATE players SET NickOld = {$row['Nick']} AND Nick = '$nick' WHERE UID = '$uid'");

So, is it merely a syntax error? Or am I approaching it the wrong way?

6 Years
Discussion Span
Last Post by ctpsolo

You got your quotes wrong.

$query = "SELECT * FROM players WHERE UID='$uid';


$query = "SELECT * FROM players WHERE UID='$uid'";

And use a decent editor with syntax highlighting. I recommend EditPad++.

Edited by smantscheff: n/a


Thanks guys! I noticed it eventually, never done that much PHP and that combined with using notepad was a huge fail. Need to get a proper editor.

Anyway after solving that I stumbled upon another error, it simply refused to update the players accordingly. It wouldn't throw an mysql error, it simply didn't update even though there was a matching record in db to update. So I used mysql_info() and saw I had warnings on the update query. Took me a while to figure out cause I didn't know how to retrieve the warnings (the query thing in phpmyadmin didn't complain either). Eventually I removed "AND" from the update query and simply used a comma which made the query execute as expected and update the record!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.