Jump to content

[SOLVED] Insert empy variable into mysql table


warstormer

Recommended Posts

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??

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...

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

 

 

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());

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.