0

I have a query that get's fed these variables (but from a POST form):

$username = "John";
$email = "johnsmith@mail.com";
$passwordEnc = "9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684";
$activated = 0;
$activationKey = "5753a498f025464d72e088a9d5d6e872592d5f91";

The query is as follows:

$stmt = $dbu->prepare("INSERT INTO users (username, email, password, activated, key) VALUES (?, ?, ?, ?, ?)");
$stmt->execute(array($username, $email, $passwordEnc, $activated, $activationKey));

There is no error, but the entry isn't added to my table named 'users'.

3 Answers3

6

You need to escape reserved words in MySQL like password and key with backticks

INSERT INTO users (username, email, `password`, activated, `key`) VALUES ...
juergen d
  • 201,996
  • 37
  • 293
  • 362
2

I checked http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html, just to save you some time 'Key' is the only word reserved on there.

0
$dbu->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbu->errorInfo();

add this lines to get any pdo query error

Man Programmer
  • 5,300
  • 2
  • 21
  • 21