我无法从我的mysql数据库加载信息。 我想从我的数据库加载数据并将其与php变量进行比较,但它不起作用。每当我加载页面时,我都会看到一个白页。
有人能帮助我吗?
<?php
define('DB_SERVER', '');
define('DB_USERNAME', '');
define('DB_PASSWORD', '');
define('DB_DATABASE', '');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if($_SERVER["REQUEST_METHOD"] == "POST") {
$myusername = mysqli_real_escape_string($db,$_POST['login']);
$mypassword = mysqli_real_escape_string($db,hash('ripemd160', $_POST['pass']));
$sql = "SELECT username, password, active FROM User WHERE username = '$myusername' and password = '$mypassword'";
$result = mysqli_query($db, $sql);
while($row = mysql_fetch_assoc($result))
{
$username = $row['username'];
$password = $row['password'];
$active = $row['active'];
if($username == $myusername){
if($active == 1)
{
session_start();
$_SESSION["login"] = $myusername;
echo $_SESSION["login"];
header("Location: http://www.example.de");
}
else
{
echo "please verify your email";
}
}
}
}
else
{
header("Location: http://www.fapsite.de/Main/Home/Views/Login/WrongPassword.php");
}
?>
答案 0 :(得分:2)
当您尝试获取用户名时,您可以访问$row['Username']
,而密钥应为username
,请注意第一个字母的大小写。这就是评估$username == $myusername
未评估为true
的原因。
与Password
vs password
和Active
vs active
相同的应用。
答案 1 :(得分:0)
这至少是代码中的致命错误:
获取时需要使用mysqli函数而不是mysql_fetch_assoc