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

报告相同问题?

悬赏问题

  • ¥20 使用hackrf进行信号收发时接收到的信号幅度太小
  • ¥20 有偿,求个自动门设计思路
  • ¥15 心率变异性联合机器学习预测子宫颈癌 FIGO 分期
  • ¥15 WebSocket的问题
  • ¥15 BDSBAS-B1C和B1C信号有什么不同
  • ¥15 在半圆平面内随机生成点坐标
  • ¥15 系统容量变化的几种多址方式TDMA, CDMA,FDMA,OFDMA 对比,应该给的是一个曲线 图,随着系统容量的增加,几种多址方式性能的对比 图,MATLAB程序仿真折线图
  • ¥15 用visual Studio 写c ++只运行上一个旧代码的运行结果是怎么回事
  • ¥15 系统容量变化的几种多址方式(TDMA,FDMA,OFDMA,CDMA)对比(相关搜索:曲线图)
  • ¥15 worldclim 历史及未来气候数据矫正