php - 我的登录页面无法使用

标签 php mysql mysqli

选择查询不工作。尽管我输入了正确的密码,但它直接进入登录失败

我从另一个数据库尝试过,它可以工作,但从这个表来看,它不想工作。

另一件事是每当我启动 XAMPP 时它都会显示 key _ buffer。

这就是阻止我的查询工作的原因吗?

下面是我的代码。希望开发者能够提供一些帮助。

<?php 
session_start();
$_SESSION['message']=''; 
$mysqli=new MySQLi('127.0.0.1','root','','learning_malaysia');

if(isset($_POST['login'])) {
    $username = $mysqli->real_escape_string($_POST['username']);
    $password = md5($_POST['password']);
    $sql="SELECT * FROM tutor_register WHERE username='$username' AND password='$password' LIMIT 1;";
    $result = mysqli_query($mysqli,$sql);

    if(mysqli_num_rows($result) > 0){
        $row = mysqli_fetch_array($result);
        if (($row['username']=='sithi') && ($row['password']=='202cb962ac59075b964b07152d234b70')){
            $_SESSION['user_type'] = $row;
            $_SESSION['password'] = $row;
            $_SESSION['message'] =  "Registration successful!";
            header("location:myresuming.html");
            exit();

        } else {
            $_SESSION['username'] = $row['username'];
            $_SESSION['profile'] = $row['profile'];
            $_SESSION['message'] =  "Registration successful!";
            header("location:Welcome.php");
            exit();
        }

    } else {
        $_SESSION['message'] = "Login Failed!"; 
    }
} 

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>form in Design</title>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
<link rel="stylesheet" type="text/css" href="form.css" />
</head>
<body>
<div class="container"><?=$_SESSION['message']?>
<img src="5.jpg" />
<form class="form" action="" method="post" enctype="multipart/form-data" autocomplete="off">
      <div class="alert alert-error"></div>
      <input type="text" placeholder="User Name" name="username" required />
      <input type="password" placeholder="Password" name="password" autocomplete="new-password" required />
 <input type="submit" name="login" value="login" class="btn-login" />

</form>
</div>
</body>
</html>

最佳答案

<?php 
session_start();
$_SESSION['message']=''; 
$mysqli=new MySQLi('127.0.0.1','root','','learning_malaysia');

if(isset($_POST['login'])) {
    $username = $mysqli->real_escape_string($_POST['username']);
    $password = md5($_POST['password']);
    $sql="SELECT * FROM tutor_register WHERE username='$username' AND password='$password' LIMIT 1;";
    $result = mysqli_query($mysqli,$sql);

    if(mysqli_num_rows($result) > 0){
        $row = mysqli_fetch_array($result);
        if (($row['username']=='sithi') && ($row['password']=='202cb962ac59075b964b07152d234b70')){
            $_SESSION['user_type'] = $row['user_type'];
            $_SESSION['password'] = $row['password'];
            $_SESSION['message'] =  "Registration successful!";
            header("location:myresuming.html");
            exit();

        } else {
            $_SESSION['username'] = $row['username'];
            $_SESSION['profile'] = $row['profile'];
            $_SESSION['message'] =  "Registration successful!";
            header("location:Welcome.php");
            exit();
        }

    } else {
        $_SESSION['message'] = "Login Failed!"; 
    }
} 
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>form in Design</title>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
<link rel="stylesheet" type="text/css" href="form.css" />
</head>
<body>
<div class="container"><?php echo $_SESSION['message']; ?>
<img src="5.jpg" />
<form class="form" action="" method="post" enctype="multipart/form-data" autocomplete="off">
      <div class="alert alert-error"></div>
      <input type="text" placeholder="User Name" name="username" required />
      <input type="password" placeholder="Password" name="password" autocomplete="new-password" required />
 <input type="submit" name="login" value="login" class="btn-login" />

</form>
</div>
</body>
</html>

试试这个。

关于php - 我的登录页面无法使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50771810/

相关文章:

mysql - 使用 Amfphp 作为 Flex 强类型对象获取 MySQL 数据时的最佳实践是什么

PHP 购物篮问题

javascript - 通过 Ajax PHP 从 Javascript onClick 更新数据库

php - Rancher 操作系统 : generate data in one container and set as environment variable in another container

PHP XAMPP 本地网络问题

php - 在我的情况下将 jenkins 服务器放在哪里

php - MySQL Rank 升级要求

php - html 表单和 php post 不起作用,信息正在被重写

php - 如何根据数据库结果将多个 PHP 复选框设置为选中状态?

php - 使 php 函数递归