Received above error at db_functions.php:21
Below is my code:
- config.php
define("DB_HOST","localhost");
define("DB_USER","root");
define("DB_PASSWORD","");
define("DB_DATABASE","test_db");
2)db_connect.php
class DB_Connect {
private $conn;
public function connect(){
require_once 'config.php';
$this->conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
return $this->conn;
}
}
3)db_functions.php
class DB_Functions{
private $conn;
function _construct() {
require_once 'db_connect.php';
$db = new DB_Connect();
$this->conn = $db->connect();
}
function _destruct() {
}
/*
* Check user exists and reture true/false
*/
function checkExistsUser($mobile) {
$stmt = $this->conn->prepare("SELECT * FROM Users WHERE Mobile=?");
$stmt->bind_parm("s", $mobile);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows > 0) {
$stmt->close();
return true;
} else {
$stmt->close();
return false;
}
}
}
4)register.php
require_once 'db_functions.php';
$db = new DB_Functions();
$response = array();
if(isset($_POST['mobile']) && isset($_POST['name']) && isset($_POST['birthdate']) && isset($_POST['address']) && isset($_POST['area']) && isset($_POST['city']) ){
$mobile = $_POST['mobile'];
$name = $_POST['name'];
$birthdate = $_POST['birthdate'];
$address = $_POST['address'];
$area = $_POST['area'];
$city = $_POST['city'];
if($db->checkExistsUser($mobile)){
$response["error_msg"] = "User already exists with ".$mobile;
echo json_encode($response);
} else {
//Create new user
$user = $db->registerNewUser($mobile, $name, $birthdate, $address, $area, $city);
if($user){
$response["mobile"] = $user["Mobile"];
$response["name"] = $user["Name"];
$response["birthdate"] = $user["Birthdate"];
$response["address"] = $user["Address"];
$response["area"] = $user["Area"];
$response["city"] = $user["City"];
echo json_encode($response);
} else {
$response["error_msg"] = "Unknow error occured in registration!";
echo json_encode($response);
}
}
} else {
$response["error_msg"] = "Required parameter (mobile, name, birthdate, address, area, city) is missing!";
echo json_encode($response);
}
For testing purpose, called register.php in Advanced REST client then received above error message.
Could you please let me know how to resolve this issue.
Thanks in advance.