我试图让我的登录主页工作,但我'总是得到以下错误: "警告:mysql_num_rows()期望参数1是资源" 在getData方法中,我尝试返回true作为结果以在loginController.php中启动会话
private function getData(){
$query ="SELECT * FROM 'users' WHERE 'username' = '$this->username'
AND 'password' = '$this->password'";
$sql = mysql_query($query) ;
if(mysql_num_rows($sql)>1){
return TURE;
}else{
throw new Exception("Username or password is invalid, please try again!");
}
}
<?php
if (isset($_POST['submit']) AND $_POST['submit']== 'Login') {
$username = $_POST['username'];
$password = $_POST['password'];
try{
include "./models/login.php";
$login = new Login($username, $password);
if ($login== TRUE) {
session_start();
$_SESSION['username'] = $username;
header('Location: index.php');
}
}catch(Exception $exc ){
echo $exc->getMessage();
}
}
?>