Icebergness Posted February 17, 2012 Share Posted February 17, 2012 Hi, I am trying to update two columns on one table from a form. The table is called pages, and there are three columns: id (auto-increments) name content When I try to update 'name' and 'content', I get the following error: 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. The form simply calls the following script on submittal : <?php $name = $_POST[name]; $content = $_POST[content]; include ("../index_files/mysql_include.php"); $result = mysql_query("UPDATE pages SET name = '$name', content = '$content' WHERE id = $id"); if (!mysql_query($result, $connection)) { die('Error: ' . mysql_error()); } mysql_close($connection); ?> Can anyone see where I'm going wrong? I've tried several different variations of the code with no joy. I should point out that the above code does update MySQL successfully, but it keeps coming out with this error which I'd rather not have Thanks, Dave Link to comment https://forums.phpfreaks.com/topic/257190-error-with-update-syntax/ Share on other sites More sharing options...
AyKay47 Posted February 17, 2012 Share Posted February 17, 2012 you are calling mysql_query() on a query resource. if (!mysql_query($result, $connection)) { die('Error: ' . mysql_error() . "<br />" . $sql); } It should read something like this: $sql = "UPDATE pages SET name = '$name', content = '$content' WHERE id = $id" $result = mysql_query($sql); if (!$result) { die('Error: ' . mysql_error() . "<br />" . $sql); } Link to comment https://forums.phpfreaks.com/topic/257190-error-with-update-syntax/#findComment-1318353 Share on other sites More sharing options...
Icebergness Posted February 17, 2012 Author Share Posted February 17, 2012 Oooh, the easy fixes are always the best. That worked perfectly. Thanks for the quick advice! Link to comment https://forums.phpfreaks.com/topic/257190-error-with-update-syntax/#findComment-1318360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.