0

Hello i am trying to insert data to phpmyadmin database. When i try from Postman i get the error " Fatal error: Call to a member function bind_param() on boolean ".

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

Obviously the prepare() function returns false. I cannot understand why. I changes the types of variables to avoid any conflicts but this doesnt seem to be the problem. Any ideas?

Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
Thomas Athanasiou
  • 121
  • 1
  • 2
  • 11
  • 1
    Your quotes in your SQL are all wrong. I also don't see you execute the query anywhere. And `respone` isn't the same as `response`. – Jonnix Sep 27 '18 at 11:02
  • 1
    Your prepare is failing because you have `'` in your query where you should have `\`` – Nick Sep 27 '18 at 11:03
  • 1
    Use [password_hash](http://php.net/manual/en/function.password-hash.php) and [password_verify](http://php.net/manual/en/function.password-verify.php) for passwords, not MD5. – Peter Sep 27 '18 at 11:07

0 Answers0