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
https://forums.phpfreaks.com/topic/244217-connecting-to-mysql/
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 ('','[email protected]','test','te' at line 1

Link to comment
https://forums.phpfreaks.com/topic/244217-connecting-to-mysql/#findComment-1254282
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
https://forums.phpfreaks.com/topic/244217-connecting-to-mysql/#findComment-1254284
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.