Jump to content

connecting to MySQL


bassy

Recommended Posts

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.";

}

 

?>

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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')";

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.