herschen Posted September 19, 2010 Share Posted September 19, 2010 I'm using the following code, but can't identify why the variable $usage, $_POST['usage'], or the usage field in my mysql database causes problems. If I take out usage, everything works fine. Any other combination of fields (when usage is included) gives me 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 'usage, package, comment. Usage is a varchar field with 100 characters (the same as all the other fields) and $_POST['usage'] is a text field that contains the year '2010', '2011', etc. Here's the code: $date = date('Y-m-d'); $typeofinquiry = $_POST['typeofinquiry']; $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $propertyid = $_POST['id']; $bldg = $_POST['bldg']; $size = $_POST['size']; $usage = $_POST['usage']; $package = $_POST['multiples']; $comments = $_POST['comments']; if ($clientemailexist == 0) { $query = "INSERT INTO clients (date, typeofinquiry, name, email, phone, propertyid, bldg, size, usage, package, comments) VALUES ('$date', '$typeofinquiry', '$name', '$email', '$phone', '$propertyid', '$bldg', '$size', '$usage', '$package', '$comments')"; mysql_query($query) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/213843-you-have-an-error-in-your-sql-syntax/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 19, 2010 Share Posted September 19, 2010 http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html Usage is also a reserved keyword. Either rename your column to something else or enclose it in back-ticks `` every time you use it in a query. Quote Link to comment https://forums.phpfreaks.com/topic/213843-you-have-an-error-in-your-sql-syntax/#findComment-1112970 Share on other sites More sharing options...
kickstart Posted September 19, 2010 Share Posted September 19, 2010 Hi Also, what is the value of useage? It is advisable to use mysql_real_escape_string to make the contents safe to use in queries. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/213843-you-have-an-error-in-your-sql-syntax/#findComment-1112971 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.