airete Posted June 8, 2007 Share Posted June 8, 2007 hello, When i try and update the database table i get this 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 'desc='My name is ***** and I\'m a 17-yr. old junior. I play electric ba' at line 1 what i am doing is having the user fill in a large text area and saving it to a database. So i think the problem could possibly be that they are using ' and " in textarea to mess it up? here is the form: echo " <form name=\"myForm\" method=\"post\" action=\"$PHP_SELF\"> Name:<br /> <input name='name' type='text' value='$bioName' size='50' /> <br /> <br /> About: <br /> <textarea name='desc' cols='65' rows='10'>$bioDesc</textarea> <br /> </label><br /> <input type=\"hidden\" name=\"action\" value=\"bioEditDone\"> <input type=\"hidden\" name=\"bioId\" value=\"$bioId\">\n <input type=\"submit\" name=\"bioSubmit\" value=\"Submit\"> </form>"; and here is the update code: if((count($_POST)>0) && ($_POST['action'] == "bioEditDone")){ $id = $_POST['id']; $name = $_POST['name']; $desc = $_POST['desc']; $query = "UPDATE family set name='$name', desc='$desc' where id=$id"; mysql_query($query) or die("Error, upate query failed <br />".mysql_error()." <br />$sql"); $action = "viewAll"; } Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/54691-solved-php-update-mysql-database-syntax-error/ Share on other sites More sharing options...
trq Posted June 8, 2007 Share Posted June 8, 2007 desc is a reserved word in sql, reserved words can be escaped in mysql by surrounding them in `backticks`. eg; $query = "UPDATE family SET name = '$name', `desc` = '$desc' WHERE id = $id"; Quote Link to comment https://forums.phpfreaks.com/topic/54691-solved-php-update-mysql-database-syntax-error/#findComment-270471 Share on other sites More sharing options...
airete Posted June 8, 2007 Author Share Posted June 8, 2007 ok, that cleared up that error. Now i am getting an error but the error feedback is not really helping me at all. 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 '' at line 1 here is the update mysql part again. I changed the variable and the name in the table if((count($_POST)>0) && ($_POST['action'] == "bioEditDone")){ $id = $_POST['id']; $name = $_POST['name']; $descr = $_POST['descr']; $query = "UPDATE family SET name = '$name', descr = '$descr' WHERE id = $id"; mysql_query($query) or die("Error, upate query failed <br />".mysql_error()." <br />$sql"); $action = "viewAll"; } Quote Link to comment https://forums.phpfreaks.com/topic/54691-solved-php-update-mysql-database-syntax-error/#findComment-270476 Share on other sites More sharing options...
airete Posted June 8, 2007 Author Share Posted June 8, 2007 Do i need to post more information? Quote Link to comment https://forums.phpfreaks.com/topic/54691-solved-php-update-mysql-database-syntax-error/#findComment-270682 Share on other sites More sharing options...
MemphiS Posted June 8, 2007 Share Posted June 8, 2007 try.. $query = "UPDATE `family` SET `name` = '$name', `descr` = '$descr' WHERE `id` = '$id'"; mysql_query($query) or die("Error, upate query failed <br />".mysql_error()." <br />$sql"); Quote Link to comment https://forums.phpfreaks.com/topic/54691-solved-php-update-mysql-database-syntax-error/#findComment-270694 Share on other sites More sharing options...
airete Posted June 8, 2007 Author Share Posted June 8, 2007 WOO! that worked thankyou!! Quote Link to comment https://forums.phpfreaks.com/topic/54691-solved-php-update-mysql-database-syntax-error/#findComment-271169 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.