当前位置: 首页 > 知识库问答 >
问题:

致命错误:调用成员函数bind_param()的布尔值在[重复]

易弘阔
2023-03-14

密码

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个答案

闾丘树
2023-03-14

预处理语句中最常见的故障之一是连接编码。。尝试

$mysqli->set_charset("utf8");

之后

$mysqli = new mysqli("host", "user", "pass", "db"); 
罗伟兆
2023-03-14

prepare语句似乎失败了(否则它将返回PDO语句而不是布尔值)

你应该使用$db-

原因可能是,您的语句中有一些字段不存在,或者您命名错误。

鲁华皓
2023-03-14

看起来像$db-

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

    }
}
 类似资料: