I found one very cool scirpt for lost password but this row is making me problems
$r = mysql_query('INSERT INTO `keys` (username,key, vreme) VALUES ("'.$user.'", "'.$acckey.'", "'.$keyexp.'"') or die(mysql_error());
error
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 'key, vreme) VALUES ("123123", "1ed2f5100a26298a55b2935cbea7d4a0", "1337991670"' at line 1
KEY
is a Reserved Word. As documented under Schema Object Names:
If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it. (Exception: A reserved word that follows a period in a qualified name must be an identifier, so it need not be quoted.)
[ deletia ]The identifier quote character is the backtick (“
`
”):mysql> SELECT * FROM `select` WHERE `select`.id > 100;
If the
ANSI_QUOTES
SQL mode is enabled, it is also permissible to quote identifiers within double quotation marks:mysql> CREATE TABLE "test" (col INT); ERROR 1064: You have an error in your SQL syntax... mysql> SET sql_mode='ANSI_QUOTES'; mysql> CREATE TABLE "test" (col INT); Query OK, 0 rows affected (0.00 sec)
Therefore:
mysql_query("INSERT INTO `keys` (username, `key`, vreme) VALUES ('$user', '$acckey', '$keyexp') ")
key
is a reserved keyword - enclose it in backticks
`key`
$r = mysql_query("INSERT INTO `keys` (username,`key`,vreme) VALUES ('$user', '$acckey','$keyexp')") or die(mysql_error());
Thank you all (:
also remove the double quotes within the query and encapsulate the query within double instead of single quotes.
use single quotes in the query to encapsulate values.
$r = mysql_query("INSERT INTO `keys` (username,key,vreme) VALUES ('".$user."', '".$acckey."','".$keyexp."')") or die(mysql_error());
Are you missing a single quote at the end of your query between the last close bracket and semi-colon?
来源:https://stackoverflow.com/questions/10762380/mysql-error-in-your-sql-syntax-near-key