致命错误:在布尔值上调用成员函数bind_param()。 PHP错误

时间:2018-09-27 11:00:55

标签: php mysql mysqli

您好,我正在尝试将数据插入phpmyadmin数据库。当我从Postman尝试时,出现错误“致命错误:在布尔值上调用成员函数bind_param()”。

DBOperations.php

    <?php

class DBOperations
{
    private $con;

    function __construct()
    {
        require_once dirname(__FILE__) . '/DbConnect.php';

        $db = new DbConnect();

        $this->con = $db->connect();
    }

    function createUser($name, $surname, $age, $username, $pass, $identity)
    {
        $password = md5($pass);
        echo $this->con->error;
        $statement = $this->con->prepare("INSERT INTO 'user_data' ('id','name', 'surname', 'age', 'username', 'password','identity') VALUES (NULL, ?, ?, ?, ?, ?,?);");
        $statement->bind_param("ssssss", $name, $surname, $age, $username, $password, $identity);


    }

}
?>

registerUser.php

<?php

require_once'../includes/DBOperations.php';
$response = array();

if($_SERVER['REQUEST_METHOD']=='POST'){

    if (isset($_POST['name']) and isset($_POST['surname']) and isset($_POST['age']) and isset($_POST['username']) and isset($_POST['password']) and isset($_POST['identity'])) {

        $db = new DBOperations();
       if( $db->createUser(
            $_POST['name'],
            $_POST['surname'],
            $_POST['age'],
            $_POST['username'],
            $_POST['password'],
            $_POST['identity']
        )) {
            $respone['error']= false;
            $respone['message']="User registered successfully";
        }
            else {
                $respone['error']= true;
                $respone['message']= "Some error occured through Registration";
            }
        }


    else {
        $respone['error']= true;
        $respone['message']= "Required fields are missing";
    }
}
else {
    $respone['error'] = true;
    $respone['message'] = "Invalid Registration Request";
}

echo json_encode($respone);

?>

enter image description here

显然,prepare()函数返回false。我不明白为什么。我更改了变量的类型,以避免任何冲突,但这似乎不是问题。有任何想法吗?

0 个答案:

没有答案