I’ve used this exact code with a slight modification of the values in another script and it worked just fine, but this time it’s giving me errors. This is the line:
$result = mysql_query("INSERT INTO contacts (name, email, telephone, companyname, postcode, message, date) VALUES('" . $name . "', '" . $userEmail . "', '" . $telephone . "', '" . $companyName . "', '" . $message . "', '" . $date . "'") or die (mysql_error());
I’ve tried echo-ing out all of the variables with this:
<p>Name: <?php echo $name; ?>, <br />Email: <?php echo $userEmail; ?>, <br />Telephone: <?php echo $telephone; ?>, <br />Company name: <?php echo $companyName; ?>, <br />Message: <?php echo $message; ?>, <br />Date: <?php echo $date; ?>, <br /></p>
Which displays them all fine when the form is submitted. However, when I try to add them to a database it flips out and says 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
I’m assuming I’m either missing something simple, I’ve made a typo somewhere (although I’ve re-typed it to double check it wasn’t that).
Here’s the way my database is set-up:

Any ideas?
UPDATE
I added the missing ) to the query and that got rid of the first error, but now I’m getting this error when I submit it:
Column count doesn’t match value count at row 1
FIXED
I was missing the $postcode variable. Doh!
You are missing a
)at the end of you query, for theVALUES().