Your verify function does not have an object called $mysqli
, it only exist in your MysqlConnect
class’s constructor
. You can readjust your MysqlConnect
class as follows.
class MysqlConnect
{
private $db_host;
private $db_usermame;
private $db_password;
private $db_database;
private $mysqli;
public function __construct($db_host,$db_usermame,$db_password,$db_database)
{
$this->db_host = $db_host;
$this->db_usermame = $db_usermame;
$this->db_password = $db_password;
$this->db_database = $db_database;
$this->mysqli = mysqli_connect("$this->db_host", "$this->db_usermame", "$this->db_password", "$this->db_database") or die("Can't connect");
$this->mysqli->select_db("$this->db_database") or die("Can't select database");
}
public function getMysqli()
{
return $this->mysqli;
}
}
Once you have done this, then you can do something similar to the following code in your driver class which is registeruser
.
class RegisterUser
{
public $username;
public $password;
public $email;
function verify(){
$mysqlcon = new MysqlConnect('localhost','root','nistor','game');
$mysqli = $mysqlcon->getMysqli();
if (isset($_POST['register'])) {
return $username = $mysqli->real_escape_string($username);
var_dump($mysqli); exit;
}else{
echo "no";
}
}
}
3
solved Call to a member function real_escape_string() on a non-object [closed]