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 Quote Link to comment 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); } Quote Link to comment 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! Quote Link to comment 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.