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, 'warstormer@hotmail.com'' 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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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