0
我正在爲PHP創建一個簡單的登錄腳本,但我沒有收到錯誤或任何內容,但由於某種原因,此查詢不起作用。這從來沒有發生過我,我現在感到沮喪。我沒有收到Mysql錯誤,但查詢不起作用
這是php_classes文件:
<?php
//Database Connection
$database_host = "localhost";
$database_user = "root";
$database_pass = "**PASSWORD**";
$database_name = "XoticSite";
$database_connection = mysqli_connect($database_host, $database_user, $database_pass, $database_name);
if($database_connection){
echo("Connection Works!!! <br />");
}
//userclass
class User
{
public function __construct()
{
#global vars
$username = null;
$password = null;
$fname = null;
$lname = null;
$email = null;
$privilege = null;
$profilePath = null;
$trys = 0;
#*******#
}
public function checkLogin($db){
$userQuery = mysqli_query($db, "SELECT * FROM `Users` WHERE
`username`='$username' && `password`='$password' LIMIT 1") or die("MYSQL ERROR");
if(mysqli_num_rows($userQuerry) == 1){
$userArray = mysqli_fetch_array($userQuery);
$fname = $userArray['fname'];
$lname = $userArray['lname'];
$email = $userArray['email'];
$ip = $userArray['ip'];
$privilege = $userArray['privilege'];
$profile = $userArray['profile'];
return true;
}
else{
return false;
}
}
public function setData($u, $p){
$username = $u;
$password = $p;
echo $username . $password;
}
public function getData($x){
if($x == 1){
return $username;
}
if($x == 2){
return $password;
}
if($x == 3){
return $trys;
} else{
return false;
}
}
}
//Client
if(!isset($_SESSION['ClientUser'])){
session_start();
echo "Created User";
$_SESSION['ClientUser'] = new User;
}
?>
這是test.php的類:
<?php
include_once 'php_includes/php_classes.php';
$_SESSION['ClientUser']->setData("username", "12345");
if($_SESSION['ClientUser']->checkLogin($database_connection)){
echo "Login Success";
} else{
echo "Login Fail";
echo $_SESSION['ClientUser']->username;
}
?>
<html lang='en'>
<head>
<title>Test</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript">
</script>
</head>
<body>
<div id="mainWrapper">
<?php
include_once("php_templates/header.php");
?>
<div id="body">
</div>
<?php
include_once("php_templates/footer.php");
?>
</div>
</body>
</html>
每當我跑的測試,我總是登錄失敗,這shold不會發生,因爲我有數據庫中的用戶名和密碼:
Picture of the Table in the Database
我在LAMP上運行這個,特別是Ubuntu 15.10