Execute Statement error

I have only slightly modified this code from the tutorial and code at the following page.


The form loads fine but I get an error on execution. If I comment out the if statement containing the execute function the code doesn’t throw errors. I use Yahoo webhosting (not the best) and the newest php version they support is 5.3.6. Is there something about using PDO that wouldn’t be supported by this version? Aside from the fact that I am not using password_hash in this code?



require 'config.php';

$msg = '';

if(!empty($_POST['userEmail']) && !empty($_POST['userPass'])):

    $sql = "INSERT INTO users (userEmail, userPass) VALUES (:userEmail, :userPass)";
    $db = getDB();
    $stmt = $db->prepare($sql);
    $stmt->bindParam(':userEmail', $userEmail);
    $stmt->bindParam(':userPass', $userPass);

    $userEmail = $_POST['userEmail'];
    $userPass = $_POST['userPass'];
    echo $sql;
    if( $stmt->execute() ):
        $msg = 'Successfully created new user';
        $msg = 'There was an error creating the new account';


What is the exact error your are getting?

I don’t have an IDE. I’m just editing the code in a txt editor and running it in the browser. I’m just getting the typical website cannot display the page “The website has a programming error.” note.

You will need to configure your php.ini to show errors on the page.

access to the php.ini file is disabled on Yahoo web hosting. Is there a workaround to set this?

Try adding the following to the top of the php file.

ini_set("display_errors", 1);

Also, check your browser’s console from JavaScript errors that may be showing. Use Ctrl+Shft+J in Chrome to view the console.

That worked!

Fatal error: Uncaught exception ‘PDOException’ with message ‘SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘’ for key ‘user_name’’ in /register.php:24 Stack trace: #0 /register.php(24): PDOStatement->execute() #1 {main} thrown in /register.php on line 24

Now you have a way to track down the error.

That is a huge help. Thanks again.

It looks like I’m trying to duplicate a value in the database that requires a unique entry. I will have to validate the input first.

1 Like