我无法转到首页,这是我无法从数据库读取的问题
<?php
include_once('user.php');
if(isset($POST['submit'])){
$username=$_POST['user'];
$password=$_POST['pass'];
$object = new Users();
$object->Login($username , $password);
}
include_once ('connection.php');
class Users{
private $db;
public function __constuct(){
$this->db = new Connection();
$this->db = $this->db->dbConnect();
}
public function Login($username , $password){
if(!empty($name) && !empty($pass)){
$st = $this->db->prepare("select * from users where username =? and password =? ");
$st->bindParam(1, $username);
$st->bindParam(2, $password);
$st->execute();
if($st->rowCount() ==1){
header("location:home.php");
}else{
echo"wrong";
}
}else{
echo"enter username & password";
}
}
}
?>
答案 0 :(得分:0)
问题多于答案... 这些文件是什么?它们在同一目录中吗?它们是否包含任何html?或者,也许是您的功能?
include_once('user.php');
include_once ('connection.php');
您永远不会定义此变量。
private $db;
您要调用这些函数还是创建它们?
public function __constuct(){...
public function Login($username , $password){...
确保大写“ Location”(在此处退出也是一种好习惯),并再次检查以确保“ home.php”页面与脚本位于同一目录。
exit(header("Location:home.php"));
这些都是让我挠头的事情。您的问题可能很简单,因为您没有大写“位置”,但我怀疑这更多是结合在一起的。