gpt4 book ai didi

php - fatal error : Call to a member function bind_param() on boolean in

转载 作者:行者123 更新时间:2023-11-29 21:53:43 35 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Fatal error: Call to a member function bind_param() on boolean [duplicate]

(12 个回答)


6年前关闭。




代码

if(isset($_POST['create'])){
$fname = trim($_POST['fname']);
$lname = trim($_POST['lname']);
$ftname = trim($_POST['ftname']);
$mtname = trim($_POST['mtname']);
$date_of_admission = trim($_POST['date_of_admission']);
$date_of_birth = trim($_POST['date_of_birth']);
$photo_location = trim($_POST['photo_location']);
$address = trim($_POST['address']);
$phone = trim($_POST['phone']);
$sex = trim($_POST['sex']);
$nationality = trim($_POST['nationality']);
$religion = trim($_POST['religion']);

if(empty($fname) && empty($lname) &&empty($ftname) &&empty($mtname) &&empty($date_of_admission) && empty($phone) && empty($sex)){
$error = "You must fill all fields.";
}else{
$insert = $db->prepare("INSERT INTO st_info (fname, lname, ftname, mtname, date_of_birth, date_of_admission, photo_location, address, phone, sex, nationality, religion,joined) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())");
$insert->bind_param('sssssssssddd',$fname,$lname,$ftname,$mtname,$date_of_birth,$date_of_admission,$photo_location,$address,$phone,$sex,$nationality,$religion);
if($insert->execute()){
//$success = "st_info added successfully!";
header("location:index.php");
}
}
}

错误

Fatal error: Call to a member function bind_param() on boolean in C:\xampp\htdocs\create.php on line 26

最佳答案

看起来 $db->prepare() 返回一个 bool 值而不是一个对象。试试这个可能吗?

if(isset($_POST['create'])){
$fname = trim($_POST['fname']);
$lname = trim($_POST['lname']);
$ftname = trim($_POST['ftname']);
$mtname = trim($_POST['mtname']);
$date_of_admission = trim($_POST['date_of_admission']);
$date_of_birth = trim($_POST['date_of_birth']);
$photo_location = trim($_POST['photo_location']);
$address = trim($_POST['address']);
$phone = trim($_POST['phone']);
$sex = trim($_POST['sex']);
$nationality = trim($_POST['nationality']);
$religion = trim($_POST['religion']);


if(empty($fname) && empty($lname) &&empty($ftname) &&empty($mtname) &&empty($date_of_admission) && empty($phone) && empty($sex)){
$error = "You must fill all fields.";
}else{
$db->prepare("INSERT INTO st_info (fname, lname, ftname, mtname, date_of_birth, date_of_admission, photo_location, address, phone, sex, nationality, religion,joined) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())");
$db->bind_param('sssssssssddd',$fname,$lname,$ftname,$mtname,$date_of_birth,$date_of_admission,$photo_location,$address,$phone,$sex,$nationality,$religion);
if($db->execute()){
//$success = "st_info added successfully!";
header("location:index.php");
}

}
}

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

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