I'm trying to insert a md5 hash into a mysql database table with php.
$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());
This query returns the 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
But the same query works well when I leave out the key column and its value. So what is the problem here? Mysql:
key varchar(128) utf8_general_ci
key is a reserved word in MySQL. Enclose it in backticks !
Like this..
$query = "INSERT INTO confirm (`key`, angemelde
^ ^ ------ Like that
This(mysql_*) extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. Switching to PreparedStatements is even more better to ward off SQL Injection attacks !
^ ^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With