I have an old code which uses mysql as its extension to communicate with MySQL. The problem is, I couldn't find the equivalent of the mysql_result
to convert this code to mysqli.
As you've seen, the SQL code will execute and check the result whether it is 0 or 1 and above. (if 0, then false. if more than 1, then true)
if (empty($_POST)===false) {
$username = $_POST['username'];
$password = $_POST['password'];
$me = new me($username, $password);
if (empty($username)===true||empty($password)===true) {
die("error1");
} else if ($me->checkexist===false) {
die("error2");
} else {echo "true";}
}
in class file:
class me {
public $uname;
public $pswd;
public function __construct($uname, $pswd) {
$this->username = $uname;
$this->password = $pswd;
}
public function checkexist() {
$sql = "SELECT COUNT(`uid`) FROM `users` WHERE `username` = '$this->username'";
$result = $conn->mysqli_query($sql);
return ($result->fetch_array()[0] == 1) ? true : false;
}
}