donglin5770 2017-10-15 09:57
浏览 50
已采纳

致命错误:从Android应用程序输入String时,在php中调用boolean上的成员函数bind_param()

 public function StoreUserInfo($sid, $name, $email, $password, $ktp, $gender) {
    $hash = $this->hashFunction($password);
    $encrypted_password = $hash["encrypted"];
    $salt = $hash["salt"];

    $stmt = $this->conn->prepare("UPDATE user SET name = $name , email = $email , encrypted_password = $encrypted_password , salt = $salt, ktp = $ktp , gender = $gender WHERE sid = '$sid'");
    $stmt->bind_param("sssssss", $sid, $name, $email, $encrypted_password, $salt, $ktp, $gender);
    $result = $stmt->execute();
    $stmt->close();

    if ($result) {
        $stmt = $this->conn->prepare("SELECT name, email, encrypted_password, salt, ktp, gender FROM user WHERE sid = $sid");
        $stmt->bind_param("s", $sid);
        if ($stmt === FALSE) {
        die($mysqli->error);}
        $stmt->execute();
        $stmt-> bind_result($token1,$token2,$token3,$token4,$token5,$token6,$token7);
        while ( $stmt-> fetch() ) {
           $user["sid"] = $token1;
           $user["name"] = $token2;
           $user["email"] = $token3;
           $user["ktp"] = $token6;
           $user["gender"] = $token7;
        }
        $stmt->close();
        return $user;
    } else {
        $response["error"] = TRUE;
        $response["error_msg"] = "Unknown error occurred in input!";
        echo json_encode($response);
      return false;
    }
}

I have this code and error shows

Fatal error: Call to a member function bind_param() on boolean in line 7

do I should not use prepare() on UPDATE ?

but when I remove it, it shows same error in line 13

then I need bind_param() right ?

what should I do ?

by the way my input updated in table, but i want to check it and return it true.

  • 写回答

1条回答 默认 最新

  • doulang9521 2017-10-15 10:13
    关注

    You're using prepare / bind the wrong way...

    The mysqli_ nameless version :

    $stmt = $this->conn->prepare('UPDATE user 
        SET name = ?, 
            email = ? , 
            encrypted_password = ? , 
            salt = ?, 
            ktp = ?, 
            gender = ? 
        WHERE sid =?');
    
      $stmt->bind_param("sssssss", 
            $name, 
            $email, 
            $encrypted_password, 
            $salt, 
            $ktp, 
            $gender,
            $sid
            );
    
      $result = $stmt->execute();
    

    The PDO one :

    $stmt = $this->conn->prepare('UPDATE user 
        SET name = :name, 
            email = :email , 
            encrypted_password = :encrypted_password , 
            salt = :salt, 
            ktp = :ktp, 
            gender = :gender 
        WHERE sid =:sid');
    // $stmt->bind_param("sssssss", $sid, $name, $email, $encrypted_password, $salt, $ktp, $gender);
    $result = $stmt->execute(array(
            ':name'=>$name, 
            ':email'=>$email, 
            ':encrypted_password'=>$encrypted_password, 
            ':salt'=>$salt, 
            ':ktp'=>$ktp, 
            ':gender'=>$gender,
            ':sid'=>$sid,
            )
        );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有偿求qftp工具。能连接,下载文件,发送代码,windows环境,最好qt6 要qt creator写的
  • ¥70 刚刚看到一个人的网站居然是通过cname访问的
  • ¥15 Attributeerror:super object has no attribute '__sklearn_tags__'_'
  • ¥15 逆置单链表输出不完整
  • ¥15 宇视vms-B200-A16@R启动不了,如下图所示,在软件工具搜不到,如何解决?(操作系统-linux)
  • ¥500 寻找一名电子工程师完成pcb主板设计(拒绝AI生成式答案)
  • ¥15 关于#mysql#的问题:UNION ALL(相关搜索:sql语句)
  • ¥15 matlab二位可视化能否针对不同数值范围分开分级?
  • ¥15 已经创建了模拟器但是不能用来运行app 怎么办😭自己搞两天了
  • ¥15 关于#极限编程#的问题,请各位专家解答!