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

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?