coxy1983 Posted June 14, 2011 Share Posted June 14, 2011 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!"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/239363-my-error-message-whats-wrong/ Share on other sites More sharing options...
redixx Posted June 14, 2011 Share Posted June 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/239363-my-error-message-whats-wrong/#findComment-1229663 Share on other sites More sharing options...
Maq Posted June 14, 2011 Share Posted June 14, 2011 In the future, please place tags around your code. Quote Link to comment https://forums.phpfreaks.com/topic/239363-my-error-message-whats-wrong/#findComment-1229666 Share on other sites More sharing options...
coxy1983 Posted June 14, 2011 Author Share Posted June 14, 2011 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/239363-my-error-message-whats-wrong/#findComment-1229667 Share on other sites More sharing options...
Maq Posted June 14, 2011 Share Posted June 14, 2011 If you're going to have spaces in your column names (which is bad practice) then you have to surround them with backtics `. Quote Link to comment https://forums.phpfreaks.com/topic/239363-my-error-message-whats-wrong/#findComment-1229679 Share on other sites More sharing options...
redixx Posted June 14, 2011 Share Posted June 14, 2011 Yeah sometimes MySQL errors aren't very helpful. 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."') "; Quote Link to comment https://forums.phpfreaks.com/topic/239363-my-error-message-whats-wrong/#findComment-1229680 Share on other sites More sharing options...
coxy1983 Posted June 14, 2011 Author Share Posted June 14, 2011 Its worked !!!!! awesome guys - thanks for your help on this. its taken me ages to do this ! Quote Link to comment https://forums.phpfreaks.com/topic/239363-my-error-message-whats-wrong/#findComment-1229689 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.