こんにちは、コードでエラーが発生しているようです。これは、変数を初期化していないが、コンストラクターで veriabile が初期化されていることを示しているようです。
Notice: Undefined variable: conn in D:\Program Files\xampp\htdocs\Tutorials\Login\classes\mysql.php on line 18
Fatal error: Cannot access empty property in D:\Program Files\xampp\htdocs\Tutorials\Login\classes\mysql.php on line 18
そして、これは私のコードです:
<?php
require_once('includes/constants.php');
class Mysql{
private $conn;
function __construct() {
$this->conn = new mysqli(DB_SERVER , DB_USER , DB_PASSWORD , DB_NAME) or
die('There was a problem connecting to the database');
}
function verify_Username_and_Pass($un , $pwd){
$query = "SELECT *
FROM users
WHERE username = ? AND password= ?
LIMIT 1";
if($stmt = $this->$conn->prepare($query)){ //this is where the error points
$stmt->bind_param('ss', $un, $pwd);
$stmt->execute();
if($stmt->fetch()){
$stmt->close;
return true;
}
}
}
}
?>
最初のif文でエラーが出ます。どうすれば解決できますか?