PHP SQL插入查询[重复]

问题描述:

I am trying this code:

public function storeUser($name, $email, $password, $Preference) {
    $uuid = uniqid('', true);
    $hash = $this->hashSSHA($password);
    $encrypted_password = $hash["encrypted"]; // encrypted password
    $salt = $hash["salt"]; // salt
        echo $Preference;

    $stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at, Preference) VALUES(?, ?, ?, ?, ?, NOW(), ?)");
    $stmt->bind_param("sssss", $uuid, $name, $email, $encrypted_password, $salt, $Preference);

    $result = $stmt->execute();
    $stmt->close();

and the above code is giving the following error:

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in /storage/ssd4/329/3219329/public_html/include/DB_Function.php on line 34 {"error":true,"error_msg":"Unknown error occurred in registration!"}

and line no 34 is:

$stmt->bind_param("sssss", $uuid, $name, $email, $encrypted_password, $salt, $Preference);

The following code is working perfectly:

public function storeUser($name, $email, $password) {
    $uuid = uniqid('', true);
    $hash = $this->hashSSHA($password);
    $encrypted_password = $hash["encrypted"]; // encrypted password
    $salt = $hash["salt"]; // salt

    $stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES(?, ?, ?, ?, ?, NOW())");
    $stmt->bind_param("sssss", $uuid, $name, $email, $encrypted_password, $salt);
    $result = $stmt->execute();
    $stmt->close();

Please help me.

Thank you.

</div>

Read the error:

Number of elements in type definition string doesn't match number of bind variables

Add an 's'. Change:

$stmt->bind_param("sssss", $uuid, $name, $email, $encrypted_password, $salt, $Preference);

For:

$stmt->bind_param("ssssss", $uuid, $name, $email, $encrypted_password, $salt, $Preference);