bassy Posted August 8, 2011 Share Posted August 8, 2011 Hey, I have been having a problem inserting data to the mySQL database and I just CAN NOT get it to work. At the moment it keeps dying at the "Error updating database. Please try again later." stage without inserting any thing to the db. I feel like I have tried everyting. Im really stuck here! I hope you guys can help. Here is the PHP code where I think the problem is. It is called by a register.php page with a form on it. This page is called register1.php. If you need more details let me know. <?php $email = strtolower(strip_tags($_POST['email'])); $restname = (strip_tags($_POST['restname'])); $cname = (strip_tags($_POST['cname'])); $phoneNum = (strip_tags($_POST['phoneNum'])); $desc = (strip_tags($_POST['desc'])); $password = md5(strip_tags($_POST['password'])); $specials = (strip_tags($_POST['specials'])); $price = (strip_tags($_POST['price'])); $foodtype = (strip_tags($_POST['foodtype'])); $reppassword = md5(strip_tags($_POST['reppassword'])); $submit = (strip_tags($_POST['submit'])); if ($submit) { //check for existance if ($email&&$password&&$reppassword&&$restname&&$cname&&$phoneNum&&$desc&&$foodtype&&$specials&&$price) { if($password==$reppassword) { //check character length of cname if (strlen ($cname)>50) { echo "Contact Name is too long. 25 character maximum."; } else { //check password length if(strlen($password)<6) { echo "Password must be at least 6 characters in length"; } else { //register the user //encrypt passowrd $password = md5($password); $reppassword = md5($reppassword); //open database $connect = mysql_connect("host","database","password") or die ('Error:' . mysql_error()); mysql_select_db("database"); $query = "INSERT INTO table (id, email, restname, cname, phoneNum, desc, password, specials, price, foodtype) VALUES ('','$email','$restname','$cname','$phoneNum','$desc','$password','$specials','$price','$foodtype')"; mysql_query($query) or die ('Error updating database. Please try again later.'); echo ("Thank you. You have been registered! <a href ='index.php'> Click here</a> to return to the home page and log in using your email and password."); } } } else echo "Passwords to not match. Please enter two identical passwords."; } else echo "Please fill in <strong>ALL</strong> required fields."; } ?> Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 change this: mysql_query($query) or die ('Error updating database. Please try again later.'); to this: mysql_query($query) or die ('Error updating database. Please try again later. '.mysql_error()); and post the error here please. Quote Link to comment Share on other sites More sharing options...
bassy Posted August 8, 2011 Author Share Posted August 8, 2011 Thanks for the quick reply. Error is: Error updating database. Please try again later. 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 'desc, password, specials, price, foodtype) VALUES ('','test@mail.com','test','te' at line 1 Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 desc is a mysql reserved word. try with backticks: (is your table really called 'table' ?) if 'id' is an auto-increment id, you can leave it out $query = "INSERT INTO `table` (`email`, `restname`, `cname`, `phoneNum`, `desc`, `password`, `specials`, `price`, `foodtype`) VALUES ('$email','$restname','$cname','$phoneNum','$desc','$password','$specials','$price','$foodtype')"; Quote Link to comment Share on other sites More sharing options...
bassy Posted August 8, 2011 Author Share Posted August 8, 2011 Thank so much for that. You fixed a complete pain in ass of a problem!! Quote Link to comment 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.