2

So here's my problem I get this error

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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) VALUES ('email@email' , '6b7d4d69e7595943da5bfb5723ceb3ef2e559275')' at line 1' in /Users/matt/Desktop/Likes/forgot/f.php on line 39

When trying to run this code

$gen = $con->prepare("INSERT INTO reset (user, key) VALUES (:user , :key)");
$gen->bindValue(':user', $username, PDO::PARAM_STR);
$gen->bindValue(':key', $token, PDO::PARAM_STR);
$gen->execute();

Any ideas? I'm binding both values so I'm not sure what's wrong. I've also went over and checked for syntax errors, but couldn't find any.

1 Answers1

2

That's because key is a reserved word. You'll either need at add backticks or choose a different name. You can look at all the reserved words here. So this is what your final code should look like

$gen = $con->prepare("INSERT INTO reset (user, `key`) VALUES (:user , :key)");
$gen->bindValue(':user', $username, PDO::PARAM_STR);
$gen->bindValue(':key', $token, PDO::PARAM_STR);
$gen->execute();
Idris
  • 997
  • 2
  • 10
  • 27