cs1h Posted October 23, 2007 Share Posted October 23, 2007 Hi, I have a script that is meant to be used to edit a row in a mysql table but its not doing it, I'm not getting any errors, its just not updating. Can anyone help? The script is <?php include "dog.php"; $email=$_POST['Email']; $name=$_POST['name']; $title=$_POST['title']; $id=$_POST['hiddenField']; $Abs=$_POST['message']; $Art=$_POST['messagetwo']; mysql_connect("localhost", "zzz", "xxx") or die(mysql_error()) ; mysql_select_db("real") or die(mysql_error()) ; mysql_query(" UPDATE items SET Email='$email', name='$name', title='$title', Abstract='$Abs', Article='$Art', WHERE id='$id'"); echo "Changes made to $title.<br /> <a href='arteditor.php'>Click here</a> to return to the admin home."; ?> Thanks Colin Quote Link to comment https://forums.phpfreaks.com/topic/74450-solved-help-editing-rows/ Share on other sites More sharing options...
trq Posted October 23, 2007 Share Posted October 23, 2007 Instead of... <?php mysql_query(" UPDATE items SET Email='$email', name='$name', title='$title', Abstract='$Abs', Article='$Art', WHERE id='$id'"); ?> Use.... <?php $sql = "UPDATE items SET Email='$email', name='$name', title='$title', Abstract='$Abs', Article='$Art', WHERE id='$id'"; if (mysql_query($sql)) { echo "Success"; } else { echo mysql_error() . "<br />$sql"; } ?> Now what do you get? Quote Link to comment https://forums.phpfreaks.com/topic/74450-solved-help-editing-rows/#findComment-376154 Share on other sites More sharing options...
otuatail Posted October 23, 2007 Share Posted October 23, 2007 WHERE id=$id it is numeric no need for quotes Quote Link to comment https://forums.phpfreaks.com/topic/74450-solved-help-editing-rows/#findComment-376158 Share on other sites More sharing options...
cs1h Posted October 23, 2007 Author Share Posted October 23, 2007 Thanks for the reply, I made the changes surgested, but I now get the following 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 'WHERE id=16' at line 1 UPDATE items SET Email='This is a system test', name='This is a system test ', title='This is a system test', Abstract='This is a system test ', Article='This is a system test ', WHERE id=16 The new script is <?php include "dog.php"; $email=$_POST['Email']; $name=$_POST['name']; $title=$_POST['title']; $id=$_POST['hiddenField']; $Abs=$_POST['message']; $Art=$_POST['messagetwo']; mysql_connect("localhost", "zzz", "xxx") or die(mysql_error()) ; mysql_select_db("real") or die(mysql_error()) ; $sql = "UPDATE items SET Email='$email', name='$name', title='$title', Abstract='$Abs', Article='$Art', WHERE id=$id"; if (mysql_query($sql)) { echo "Success"; } else { echo mysql_error() . "<br />$sql"; } ?> Any ideas why? All help is very much appreciated. Thanks Colin Quote Link to comment https://forums.phpfreaks.com/topic/74450-solved-help-editing-rows/#findComment-376160 Share on other sites More sharing options...
otuatail Posted October 23, 2007 Share Posted October 23, 2007 you could echo the sql to the webpage and copy it into the mysql admin. see if it works there. Desmond. Quote Link to comment https://forums.phpfreaks.com/topic/74450-solved-help-editing-rows/#findComment-376164 Share on other sites More sharing options...
adam291086 Posted October 23, 2007 Share Posted October 23, 2007 remove ,  out of you code before the WHERE claus Quote Link to comment https://forums.phpfreaks.com/topic/74450-solved-help-editing-rows/#findComment-376185 Share on other sites More sharing options...
cs1h Posted October 23, 2007 Author Share Posted October 23, 2007 Done that but still no luck, I'm still getting 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 'WHERE id = 16' at line 1 UPDATE items SET Email='This is a system test ', name='This is a system test ', Title='This is a system test ', Abstract='This is a system test ', Article='This is a system ', WHERE id = 16 Any more ideas, all help is appriciated. Thanks Colin Quote Link to comment https://forums.phpfreaks.com/topic/74450-solved-help-editing-rows/#findComment-376250 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.