0

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

$username = "John";
$email = "[email protected]";
$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'.

4
  • 1
    possible duplicate of How to squeeze error message out of PDO? Commented Oct 27, 2012 at 10:02
  • What does $stmt->execute return? Commented Oct 27, 2012 at 10:03
  • Please stick your prepare and execute inside a try { } catch (PDOException $e) { echo $e; } block, and tell us the results. Commented Oct 27, 2012 at 10:03
  • @Daedalus It shows no error when I do that.. Commented Oct 27, 2012 at 10:04

3 Answers 3

6

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

INSERT INTO users (username, email, `password`, activated, `key`) VALUES ...
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks that saved me a lot of time! Forgetting that often.. Will accept when I can, have a good day!
I use the MySQL workbench for designing my queries. It highlights reserved words and you can see the problem from the beginning.
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.

Comments

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

add this lines to get any pdo query error

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.