<?php
class DbOperations
{
private $con;
function __construct()
{
require_once dirname(__FILE__).'/DbConnect.php';
$db = new DbConnect();
$this->con = $db->connect();
}
public function createUser($email, $password, $gender, $dob_year, $dob_month, $dob_day, $time_registered)
{
if($this->isUserExist($email))
{
echo "0";
return 0;
}
else
{
$stmt = $this->con->prepare("insert into table_user (`id`, `email`, `password`, `gender`, `dob_year`, `dob_month`, `dob_day`, `time_registered`) values (NULL, ?, ?, ?, ?, ?, ?, ?);");
$stmt->bind_param("sssssss", $email, $password, $gender, $dob_year, $dob_month, $dob_day, $time_registered);
if($stmt->execute())
{
echo "1";
return 1;
}
else
{
echo "2";
return 2;
}
}
}
private function isUserExist($email)
{
$stmt = $this->con->prepare("select id from table_user where email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();
return $stmt->num_rows > 0;
}
}
?>
Hi, I am trying to make a registration page. createUser function works perfectly when I return true or false from isUserExists() method. It seems like $stmt->num_rows > 0; always returning false, but I see that data is saved into the database. It is supposed to change return value to true when user registers, but, it always return false. What is wrong with this?