MySQL syntax error - near '1' at line 1
mysql, php, syntax-error
Solution
You're violating the DRY principle big time. Why not something like...
$statusValue = ($status === 1) ? 1 : 2;
$sqlQuery = mysql_query("UPDATE `14d2_group` SET `status` = $statusValue WHERE `steam64` = '$id'"):
UPDATE 2: It looks like there's a need for additional clarification.
mysql_query function doesn't only create a query: it actually sends in to MySQL - and returns the result. In case of UPDATE it will return FALSE if query has failed. That's why you shouldn't call mysql_query twice, as you did in the original example.
You can check how many lines were actually updated with mysql_affected_rows function.
UPDATE 3: Finally get it. ) That was the reason error appeared: you tried to call mysql_query with result of the last update query. Which was, as TRUE converted to String, just '1'. )
Problem
When running my PHP script It keeps giving me 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 '1' at line 1` This is my sql code I have other than selecting from the table. I have commented out all of this and not gotten an error, so I'm assuming its occuring in this block of code. ``` if($status === 1){ $sqlQ = mysql_query("UPDATE tablename SET status=1 WHERE steam64='$id'"); if(!mysql_query($sqlQ, $con)){ die('Error: ' . mysql_error()); } }else if($status !== 1){ $sqlQ = mysql_query("UPDATE tablename SET status=2 WHERE steam64='$id'"); if(!mysql_query($sqlQ, $con)){ die('Error: ' . mysql_error()); } } ``` What is really confusing me is the line 1 part.