Jump to content

Recommended Posts

Hello,

 

Im am new to web design and im in the process of creating my first site.

Im trying to set up a simple form to collect customer information and save the data in a mysql database that i have set up.

 

Im getting an error message "Error updating database" when submitting the form ........ can anyone help

 

heres my coding (i have removed my credentials xxxxxxxx) :

 

<?php

$Title = $_POST['Title'];
$Forename = $_POST['Forename'];
$Surname = $_POST['Surname'];
$House_Number_or_Name = $_POST['House Number or Name'];
$Street = $_POST['Street'];
$Town_or_City = $_POST['Town or City'];
$County_or_Province = $_POST['County or Province'];
$Country = $_POST['Country'];
$Post_or_Zip = $_POST['Post or Zip'];
$Email_Address = $_POST['Email Address'];

mysql_connect("localhost", "xxxxxxxx", "xxxxxxxx") or die(mysql_error());
mysql_select_db("cheaper0_customers") or die(mysql_error());

$query="INSERT INTO customers 
(ID, Title, Forename, Surname, House Number or Name, Street, Town or City, County or Province, Country, Post or Zip, Email Address) VALUES('Null', '".$Title."', '".$Forename."','".$Surname."','".$House_Number_or_Name."','".$Street."','".$Town_or_City."','".$County_or_Province."','".$Country."','".$Post_or_Zip."','".$Email_Address."',) ";

mysql_query($query) or die ('Error updating database');

echo "Thank you for Signing Up!";

?>

Link to comment
https://forums.phpfreaks.com/topic/239363-my-error-message-whats-wrong/
Share on other sites

Change

mysql_query($query) or die ('Error updating database');

 

To

mysql_query($query) or die ('Error updating database' . mysql_error());

 

This will give you the SQL error message which will help tell what is wrong. Though I am already guessing that you have more/less fields than you do data, but I'm not going to strain my eyes and count right now.

 

EDIT: Actually, it looks like you have an extra comma after $Email_Address

'".$Country."','".$Post_or_Zip."','".$Email_Address."',) ";

 

EDIT Again: Also, if your ID is auto_increment then you don't need to include it at all in your query.

Thanks for the speedy reply, I have now updated and get this :

 

Error updating databaseYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Number or Name, Street, Town or City, County or Province, Country, Post or Zip, ' at line 2

 

 

Im probably being really dumb but i just dont understand what this means.............. although i guess i have to mess it up in order to learn for next time ?

Yeah sometimes MySQL errors aren't very helpful. :P

 

Try this:

$query="INSERT INTO customers 
(Title, Forename, Surname, `House Number or Name`, Street, `Town or City`, `County or Province`, Country, `Post or Zip`, `Email Address`) VALUES('".$Title."', '".$Forename."','".$Surname."','".$House_Number_or_Name."','".$Street."','".$Town_or_City."','".$County_or_Province."','".$Country."','".$Post_or_Zip."','".$Email_Address."') ";

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.