I have this error that I cannot fix when running my code.. I have looked online for solutions but nothing, I have no idea how to fix this.
<?php
class DbOperations
{
private $con;
function _construct()
{
require_once dirname(_FILE_).'/DBConnect.php';
$db = new DBConnect();
$this->con = $db->connect();
}
/* CRUD - Create */
function createUser($name, $surname, $student_number, $pass)
{
$password = md5($pass);
// *** The error occurs here ***
$stmt = $this->con->prepare("INSERT INTO `users` (`id`, `name`, `surname`, `student_number`, `password`) VALUES (NULL, ?, ?, ?, ?);");
$stmt->bind_param("ssss",$name,$surname,$student_number,$password);
if($stmt->execute())
{
return true;
}
else
{
return false;
}
}
}
And then my registerUser.php
<?php
require_once '../include/DbOperations.php';
$response = array();
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(
isset($_POST['name']) and
isset($_POST['surname']) and
isset($_POST['student_number']) and
isset($_POST['password']))
{
//Continue with using data
$db = new DbOperations();
if($db->createUser($_POST['name'],$_POST['surname'],$_POST['student_number'],$_POST['password']))
{
$response['error'] = false;
$response['message'] = "User registered successfully";
}
else
{
$response['error'] = true;
$response['message'] = "Some error occured, please try again.";
}
}
else
{
$response['error'] = true;
$response['message'] = "Required fields are missing";
}
}
else
{
$response['error'] = true;
$response['message'] = "Invalid Request";
}
echo json_encode($response);