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 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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路