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);
?>
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?