duanniubeng2265
2017-11-01 16:54 阅读 58
已采纳

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>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dqndc26628 dqndc26628 2017-11-01 17:08

    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);
    
    点赞 评论 复制链接分享

相关推荐