gpt4 book ai didi

php - fatal error : Call to a member function bind_param() on boolean in php while inputing String from Android app

转载 作者:行者123 更新时间:2023-11-29 10:34:18 25 4
gpt4 key购买 nike

 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;
}
}

我有这个代码并显示错误

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

我不应该在 UPDATE 上使用 prepare() 吗?

但是当我删除它时,它在第 13 行显示相同的错误

那么我需要bind_param(),对吗?

我该怎么办?

顺便说一句,我的输入已在表中更新,但我想检查它并返回 true。

最佳答案

您使用准备/绑定(bind)的方式错误...

mysqli_ 无名版本:

$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();

PDO 之一:

$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,
)
);

关于php - fatal error : Call to a member function bind_param() on boolean in php while inputing String from Android app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46753780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com