此问题在此处已有答案:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such(1个答案)
七年前就关门了。
代码
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");
}
}
}
错误
致命错误:对第26行C:\xampp\htdocs\create.php中的布尔值调用成员函数bind_param()
3条答案
按热度按时间rxztt3cl1#
看起来像$db-〉prepare()返回一个布尔值而不是一个对象。
m528fe3b2#
您的准备语句似乎失败(否则它将返回PDOStatement而不是布尔值)
应使用
$db->errorInfo()
和$db->errorCode()
获取错误原因。原因可能是语句中有一些字段不存在,或者命名错误。
vc6uscn93#
预准备语句最常见的错误之一是连接编码。. try
之后