0

Does anybody know why the following PHP code keeps throwing errors: I have been unable to log any proper error other than the if statement $result not going through and giving me the Echo 'Error' statement. Is there something wrong with my insertion?

    $new_tbl_name = 'Password_Reset';

   $sql = "INSERT INTO $new_tbl_name (Email, Key) VALUES ('$email','$resetHash')";

   $result = mysql_query($sql);


    if ($result) {
    }
    else {
       echo 'Error';
     }
1
  • 2
    Echo mysql_error() to get more specific information. Commented Oct 7, 2012 at 1:24

1 Answer 1

3

key is a reserved word, you'll have to escape it:

INSERT INTO $new_tbl_name (Email, `Key`) VALUES
                                  ^   ^

As a general suggestion, simply saying "error" is utterly useless for debugging purposes. Have mysql TELL you what's wrong:

if (!$result) {
   die(mysql_error());
}

so you have a clue as to what's wrong, instead of just poking around in the dark.

Sign up to request clarification or add additional context in comments.

2 Comments

wow. Unbelievable. Thank you for saving me from breaking some
The error message probably wouldn't have helped in this case anyway. MySQL's syntax errors tend to be very generic. All it probably would say is that the error is at the word Key, but it won't tell you WHY it's wrong.

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.