# Execute Statement error

**URL:** <https://forum.freecodecamp.org/t/execute-statement-error/173709>\
**Category:** General\
**Created:** [February 9, 2018, 3:53pm UTC](https://forum.freecodecamp.org/t/execute-statement-error/173709 "2018-02-09T15:53:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![haptonstall](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/haptonstall/32/93187_2.png) [@haptonstall](https://forum.freecodecamp.org/u/haptonstall)\
**Post date:** [February 9, 2018, 3:53pm UTC](https://forum.freecodecamp.org/t/execute-statement-error/173709/1 "2018-02-09T15:53:57Z")

</div>

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

[https://devdojo.com/episode/create-a-php-login-script](https://devdojo.com/episode/create-a-php-login-script)

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?

```auto
<?php

session_start();

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';
    else:
        $msg = 'There was an error creating the new account';
    endif;
endif;

 
?>

```

---

<div class="post-metadata">

**Author:** ![haptonstall](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/haptonstall/32/93187_2.png) [@haptonstall](https://forum.freecodecamp.org/u/haptonstall)\
**Post date:** [February 9, 2018, 4:26pm UTC](https://forum.freecodecamp.org/t/execute-statement-error/173709/3 "2018-02-09T16:26:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![haptonstall](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/haptonstall/32/93187_2.png) [@haptonstall](https://forum.freecodecamp.org/u/haptonstall)\
**Post date:** [February 9, 2018, 4:33pm UTC](https://forum.freecodecamp.org/t/execute-statement-error/173709/5 "2018-02-09T16:33:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![camperextraordinaire](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@camperextraordinaire](https://forum.freecodecamp.org/u/camperextraordinaire)\
**Post date:** [February 9, 2018, 4:35pm UTC](https://forum.freecodecamp.org/t/execute-statement-error/173709/6 "2018-02-09T16:35:06Z")

</div>

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

```auto
error_reporting(E_ALL);
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.

---

<div class="post-metadata">

**Author:** ![haptonstall](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/haptonstall/32/93187_2.png) [@haptonstall](https://forum.freecodecamp.org/u/haptonstall)\
**Post date:** [February 9, 2018, 4:37pm UTC](https://forum.freecodecamp.org/t/execute-statement-error/173709/7 "2018-02-09T16:37:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![haptonstall](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/haptonstall/32/93187_2.png) [@haptonstall](https://forum.freecodecamp.org/u/haptonstall)\
**Post date:** [February 9, 2018, 4:46pm UTC](https://forum.freecodecamp.org/t/execute-statement-error/173709/9 "2018-02-09T16:46:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 5:59pm UTC](https://forum.freecodecamp.org/t/execute-statement-error/173709/10 "2021-01-16T17:59:06Z")

</div>

Closed on January 16, 2021, 5:59pm UTC


