graham23s Posted May 15, 2007 Share Posted May 15, 2007 Hi Guys, i'm getting an error in my syntax here but it looks fine to me the error is: 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 'WHERE `id`='4'' at line 1 heres the code: $query2 = "SELECT `views` FROM `uploaded` WHERE `id`='$id'"; $result2 = mysql_query($query2) or die (mysql_error()); $row = mysql_fetch_array($result2) or die(mysql_error()); // put views in avariable.../////////////////////////////////////////////////////// $views = $row['views']; // if have no counter value set counter value to 1.../////////////////////////////// if(empty($views)) { $views = 1; $query3 = "INSERT INTO `uploaded` (`views`) VALUES ('$views') WHERE `id`='$id'"; $result3 = mysql_query($query3) or die (mysql_error()); } // increment the views by 1...////////////////////////////////////////////////////// $add_another_1 = $views + 1; $query4 = "UPDATE `uploaded` SET `views`='$add_another_1' WHERE `id`='$id'"; $result4 = mysql_query($query4) or die (mysql_error()); it doesn't say on what line but it all looks ok! cheers guys Graham Quote Link to comment https://forums.phpfreaks.com/topic/51567-error-in-my-syntax/ Share on other sites More sharing options...
Lumio Posted May 15, 2007 Share Posted May 15, 2007 You can't use the WHERE-Clause in INSERT INTO commands: your wrong code: $query3 = "INSERT INTO `uploaded` (`views`) VALUES ('$views') WHERE `id`='$id'"; right: $query3 = "INSERT INTO `uploaded` (`views`) VALUES ('$views')"; or: $query3 = "INSERT INTO `uploaded` SET `views` = '$views'"; Quote Link to comment https://forums.phpfreaks.com/topic/51567-error-in-my-syntax/#findComment-253939 Share on other sites More sharing options...
graham23s Posted May 15, 2007 Author Share Posted May 15, 2007 Thanks mate, noted for future reference:) Graham Quote Link to comment https://forums.phpfreaks.com/topic/51567-error-in-my-syntax/#findComment-253949 Share on other sites More sharing options...
Lumio Posted May 17, 2007 Share Posted May 17, 2007 Please click "Topic Solved" Quote Link to comment https://forums.phpfreaks.com/topic/51567-error-in-my-syntax/#findComment-255333 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.