Question:
HELP: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for?
2012-05-07 03:16:44 UTC
Hey. I've been sruggling with php and mysql all wekkend and just want to get it sorted. everytime I try and connect i get the following errror: 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 '' at line 2

Here is the code:

$connect = mysql_connect("localhost", "root", "123");
if (!$connect) {
die('Could not connect' . mysql_error());
}

$db_selected = mysql_select_db("ryan");
if (!$db_selected) {
die('Could not select database' . mysql_error());
}
?>
Three answers:
Jim
2012-05-07 03:25:54 UTC



$link = mysql_connect("localhost", "root", "123");

if (!$link) {

die('Could not connect' . mysql_error());

}



$db_selected = mysql_select_db("ryan", $link);

if (!$db_selected) {

die('Could not select database' . mysql_error());

}

?>
2012-05-07 03:55:17 UTC
Too messy for anything. And READ the mysql and php manuals. You should NEVER use the root account to access the database. ALWAYS create a user to access from the web pages. Some server installs do not permit root to access the database from scripts.

$connect = mysql_connect("localhost","created_user","user_password") or die ("Could not connect ".mysql_error());

mysql_select("database_name") or die ("Could not select database ".mysql_error());

You are far better to NOT use the strings before the mysql_error(), as the system will report these errors correctly. And then turn of error reports for an active site once you have the system working, as they can give away enough detail to aid hackers.

But if you read the error report you are getting properly, neither of your statements has more than one line. So the error is somewhere else in your script. You are looking for something like :

$res = mysql_query (select id, fname, lname, address1, address2, address3, country from user u left join addresses a on a.user_id = u.id where u.id = '99' ",$connection);

In other words the error is from a multi line statement. I normally use this for errors so that I can locate the actual cause :

//first error check, maybe the connection above :

or die("1 ".mysql_error());

Second check, maybe selecting DB :

or die("2 ".mysql_error());

Third check, the select query :

or die("3 ".mysql_error());

and keep this sequence going through the script. That way you can go straight to the particular query and save a lot of grief when the error message is as limited as the above.
?
2016-10-16 18:30:40 UTC
the region you're vacationing would be having get right of entry to to a checklist with a incorrect sq. syntax, or you would be utilising sq. to retrieve a checklist, yet your syntax is defective. positioned up your sq. question of you encountered the situation as quickly as you create the sq. fact.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...