joecooper Posted November 7, 2008 Share Posted November 7, 2008 Im trying to update a row using php in my MYSQL db, but it keeps failing. the code is this: $query = "UPDATE lotto SET state='1', winner='$user' ". "WHERE row = '$row' AND WHERE column = '$col' LIMIT 1"; //update the grid to clicked. mysql_query($query) or die(mysql_error()); ive tried taking away the second 'WHERE'. but no joy. the error is: "...right syntax to use near 'AND WHERE column = 29 LIMIT 1' at line 1" Link to comment https://forums.phpfreaks.com/topic/131802-query-errors/ Share on other sites More sharing options...
rhodesa Posted November 7, 2008 Share Posted November 7, 2008 remove the extra WHERE $query = "UPDATE lotto SET state='1', winner='$user' ". "WHERE row = '$row' AND column = '$col' LIMIT 1"; //update the grid to clicked. mysql_query($query) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/131802-query-errors/#findComment-684678 Share on other sites More sharing options...
joecooper Posted November 7, 2008 Author Share Posted November 7, 2008 yes as i said i tried that. just done it again and the error: 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 'column = '23' LIMIT 1' at line 1 Link to comment https://forums.phpfreaks.com/topic/131802-query-errors/#findComment-684682 Share on other sites More sharing options...
JonnoTheDev Posted November 7, 2008 Share Posted November 7, 2008 $query = "UPDATE lotto SET state='1', winner='".mysql_real_escape_string($user)."' WHERE row='".mysql_real_escape_string($row)."' AND column = '".mysql_real_escape_string($col)."' LIMIT 1"; Check your variables contain the correct data. Link to comment https://forums.phpfreaks.com/topic/131802-query-errors/#findComment-684683 Share on other sites More sharing options...
joecooper Posted November 7, 2008 Author Share Posted November 7, 2008 yes they do. ive just now tried to do this within PMA : UPDATE lotto SET state='1', winner='user' WHERE row='42' AND column='29' and still same error? thats not even using varibles but solid text. Link to comment https://forums.phpfreaks.com/topic/131802-query-errors/#findComment-684687 Share on other sites More sharing options...
PFMaBiSmAd Posted November 7, 2008 Share Posted November 7, 2008 http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html Link to comment https://forums.phpfreaks.com/topic/131802-query-errors/#findComment-684689 Share on other sites More sharing options...
.josh Posted November 7, 2008 Share Posted November 7, 2008 I believe your issue is that "column" is a mysql reserved word. If that's the name of your column, put backticks around it like so: `column` better yet, change your column name to something other than a reserved word, as that's bad programming practice. edit: PFM beat me to it Link to comment https://forums.phpfreaks.com/topic/131802-query-errors/#findComment-684690 Share on other sites More sharing options...
JonnoTheDev Posted November 7, 2008 Share Posted November 7, 2008 Yep you get this because column is reserved syntax. Bad choice naming your fields row & column Link to comment https://forums.phpfreaks.com/topic/131802-query-errors/#findComment-684696 Share on other sites More sharing options...
JonnoTheDev Posted November 7, 2008 Share Posted November 7, 2008 Who can type the quickest eh? Link to comment https://forums.phpfreaks.com/topic/131802-query-errors/#findComment-684699 Share on other sites More sharing options...
joecooper Posted November 7, 2008 Author Share Posted November 7, 2008 ah, would also explain why this isnt working SELECT * FROM lotto WHERE 'row'=$row AND 'column'=$col Link to comment https://forums.phpfreaks.com/topic/131802-query-errors/#findComment-684715 Share on other sites More sharing options...
JonnoTheDev Posted November 7, 2008 Share Posted November 7, 2008 That it would Link to comment https://forums.phpfreaks.com/topic/131802-query-errors/#findComment-684716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.