我试图用php将md5哈希插入到mysql数据库表中。
$key = $email . date('mY');
$key = md5($key);
$query = "INSERT INTO confirm (key, angemeldet_von, geschlecht, geburtstag)
VALUES('$key', '$angemeldet_von', '$geschlecht', '$geburtstag')";
$confirm = mysql_query($query, $connectionID)
or die('failed connecting: ' . mysql_error());
此查询返回错误:
failed connecting: 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, angemeldet_von, geschlecht, geburtstag) VALUES('8fe3ec75be1a43b49eacd3' at line 1
但是当我省略键列及其值时,同样的查询效果很好。 那么这里的问题是什么? MySQL的:
key varchar(128) utf8_general_ci
答案 0 :(得分:4)
key
是MySQL中的reserved word
。用反引号括起来!
喜欢这个..
$query = "INSERT INTO confirm (`key`, angemelde
^ ^ ------ Like that
此mysql_*
)扩展程序自PHP 5.5.0
起已弃用,将来会被删除。相反,应使用MySQLi
或PDO_MySQL
扩展名。切换到PreparedStatements
甚至可以更好地抵御SQL注入攻击!
^ ^