warstormer Posted August 6, 2007 Share Posted August 6, 2007 I've got a form in which a couple of the address fields can be empty when the form is submitted... I haven't actually managed to get the Insert statement to work yet (see other post..), but I know this seems to also be causing problems. I have set up the table fields for these 2 address form fields to be Yes under the NULL column, but it still gives the almighty: 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 ' , London, W1, UK, 9991, 007, '[email protected]'' at line 1 The actual query is: mysql_query("INSERT INTO wholesale_tbl (wholesale_id, wholesale_name, wholesale_forename, wholesale_company, wholesale_add1, wholesale_add2, wholesale_add3, wholesale_city, wholesale_zip, wholesale_country, wholesale_tel, wholesale_fax, wholesale_email) VALUES ($password, $name, $forename, $company, $add1, $add2, $add3, $city, $zip, $country, $tel, $fax, '$from'") or die(mysql_error()); Is it just me or was this all easier in sql server?? Link to comment https://forums.phpfreaks.com/topic/63524-solved-insert-empy-variable-into-mysql-table/ Share on other sites More sharing options...
ToonMariner Posted August 6, 2007 Share Posted August 6, 2007 you need to quote strings being added to the database.... note you use '$from'... all the other strings going in should be the same - you may have a function that returns these values which could yeild NULL or '$var' which would help you no end... Link to comment https://forums.phpfreaks.com/topic/63524-solved-insert-empy-variable-into-mysql-table/#findComment-316580 Share on other sites More sharing options...
warstormer Posted August 6, 2007 Author Share Posted August 6, 2007 you need to quote strings being added to the database.... note you use '$from'... all the other strings going in should be the same - you may have a function that returns these values which could yeild NULL or '$var' which would help you no end... Tried the quotes on the email variable as a test... I've now added quotes to all the strings: mysql_query("INSERT INTO wholesale_tbl (wholesale_id, wholesale_name, wholesale_forename, wholesale_company, wholesale_add1, wholesale_add2, wholesale_add3, wholesale_city, wholesale_zip, wholesale_country, wholesale_tel, wholesale_fax, wholesale_email) VALUES ('$password', '$name', '$forename', '$company', '$add1', '$add2A', '$add3A', '$city', '$zip', '$country', '$tel', '$fax', '$from'") or die(mysql_error()); but am now getting this: 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 Link to comment https://forums.phpfreaks.com/topic/63524-solved-insert-empy-variable-into-mysql-table/#findComment-316586 Share on other sites More sharing options...
warstormer Posted August 6, 2007 Author Share Posted August 6, 2007 One thing to note... there are 3 fields in the table (set as NULL = Yes) which are not referenced in the above query... would that cause a problem? Link to comment https://forums.phpfreaks.com/topic/63524-solved-insert-empy-variable-into-mysql-table/#findComment-316593 Share on other sites More sharing options...
warstormer Posted August 6, 2007 Author Share Posted August 6, 2007 After 2 hours (where I did manage to learn/tidy up a couple of things) I noticed that there was a ')' missing at the end of the VALUES list.... Works now, you live and learn.... mysql_query("INSERT INTO wholesale_tbl (wholesale_id, wholesale_name, wholesale_forename, wholesale_company, wholesale_add1, wholesale_add2, wholesale_add3, wholesale_city, wholesale_zip, wholesale_country, wholesale_tel, wholesale_fax, wholesale_email) VALUES ('$password', '$name', '$forename', '$company', '$add1', '$add2A', '$add3A', '$city', '$zip', '$country', '$tel', '$fax', '$from'") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/63524-solved-insert-empy-variable-into-mysql-table/#findComment-316599 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.