我是php(oops)的新手。我在(php)类中使用php条件时感到困惑。 我只是想用类来验证我的PHP表单。有人请帮我让我的剧本工作。
class Connect
{
public $host = "localhost";
public $username = "root";
public $password = "";
public $database = "cls";
public $mcon;
public $mdcon;
function __construct()
{
$con = mysqli_connect($this->host, $this->username, $this->password, $this->database);
if(!$con)
{
die;
}
else
{
$this->mcon= $con;
return $this->mcon;
}
}
function Seldb()
{
$condb = mysqli_select_db($this->mcon, $this->database);
$this->mdcon= $condb;
return $this->mdcon;
}
function Ucheck($uname, $upass)
{
$check = "select * from ut WHERE u_name ='$uname' and u_pass ='$upass'";
if ($uresult= mysqli_query($mdcon,$check))
{
$urows= mysqli_num_rows($uresult);
}
if ($urows == 1)
{
$_SESSION['uname'] = $uname;
$_SESSION['auth'] = 1 ;
$_SESSION['check'] = 'sesscheck' ;
header('Location:http://google.com/');
}
else
{
$war = "PLEASE enter username and password again.";
}
}
}
答案 0 :(得分:3)
应该是
if ($uresult= mysqli_query($this->$mdcon,$check))
而不是
if ($uresult= mysqli_query($mdcon,$check))
您需要使用this
关键字,否则会给您undefined variable
通知。
function Ucheck($uname, $upass)
{
$check = "select * from ut WHERE u_name ='$uname' and u_pass ='$upass'";
if ($uresult= mysqli_query($this->Seldb(),$check))
{
$urows= mysqli_num_rows($uresult);
} else { mysqli_error($this->Seldb());} //<----- Added This