Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP PDO prepare statement failure
    primarykey
    data
    text
    <p>I've been having a failure when I want to submit data for my database. The connection is established, but when I use:</p> <pre><code> $sql = $MyConnection-&gt;prepare(" INSERT INTO AMP_USERS (Username, Password, Lastname, Email) VALUES ('$username', '$password', '$lastname', '$email') "); $sql-&gt;execute(); </code></pre> <p>I get a failure. I've already done:</p> <pre><code>$sql-&gt;bindParam(:username, $username) </code></pre> <p>And so on, but that didn't work / didn't provide the error. Somehow the data doesn't gets stored into the database, and the error must be somewhere in this bit of code.</p> <p><strong>EDIT</strong></p> <p>Though I don't think all of the code is necessary I'll post it:</p> <pre><code> &lt;?php require('config.php'); if($MyConnection = new PDO('mysql:host=fdb6.biz.nf;dbname=1446018_venator', $dbusername, $dbpassword)) { echo "A connection has been made!"; } $username = $_POST['username']; $password = $_POST['password']; $lastname = $_POST['lastname']; $email = $_POST['email']; // Hasing the password: // A higher "cost" is more secure but consumes more processing power $cost = 10; // Create a random salt $salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.'); // Prefix information about the hash so PHP knows how to verify it later. // "$2a$" Means we're using the Blowfish algorithm. The following two digits are the cost parameter. $salt = sprintf("$2a$%02d$", $cost) . $salt; // Hash the password with the salt $hash = crypt($password, $salt); $sql = $MyConnection-&gt;prepare(" INSERT INTO AMP_USERS (Username, Password, Lastname, Email) VALUES (:username, :password, :lastname, :email) "); $sql-&gt;bindParam(':username', $username); $sql-&gt;bindParam(':password', $hash); $sql-&gt;bindParam(':lastname', $lastname); $sql-&gt;bindParam(':email', $email); $sql-&gt;execute(); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload