<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../admin/css/styles.css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-3 col-md-2"></div>
<div class="col-lg-6 col-md-8 login-box">
<div class="col-lg-12 login-key">
<i class="fa fa-key" aria-hidden="true"></i>
</div>
<div class="col-lg-12 login-title">
ADMIN PANEL
</div>
<div class="col-lg-12 login-form">
<div class="col-lg-12 login-form">
<form action="" method="POST">
<div class="form-group">
<label class="form-control-label">USERNAME</label>
<input type="text" name="username" class="form-control">
</div>
<div class="form-group">
<label class="form-control-label">PASSWORD</label>
<input type="password" name="password" class="form-control" i>
</div>
<div class="col-lg-12 loginbttm">
<div class="col-lg-6 login-btm login-text">
<!-- Error Message -->
</div>
<div class="col-lg-6 login-btm login-button">
<input type="submit" name="submit" class="btn btn-outline-primary">
</div>
</div>
</form>
</div>
</div>
<div class="col-lg-3 col-md-2"></div>
</div>
</div>
</body>
</html>
<?php
include 'db.php';
if(isset($_POST['submit'])){
$username=$_POST['username'];
$password=$_POST['password'];
$db=mysqli_select_db($conn,"admin");
echo $sql= "SELECT * FROM admin WHERE username='$username' AND password='$password'";
$result=mysqli_query($conn,$sql);
$rows=mysqli_num_rows($result);
if($rows == 1){
echo 'hi';
}
else{
echo 'failed';
}
}
?>
答案 0 :(得分:2)
这是因为您正在echo
实际未运行查询。
删除此
echo $ sql =“ SELECT * FROM admin WHERE username ='$ username'AND password ='$ password'”;
添加此
$ sql =“ SELECT * FROM admin WHERE username ='$ username'AND password ='$ password'”;
点对点以改善查询,
SELECT *
,这是一个坏习惯,请提及列名答案 1 :(得分:1)
echo
前面的$sql
。$username
和$password
。$rows
变量。检查它是否不同于1。答案 2 :(得分:0)
也许您在数据库中有两对相等的用户名和密码,否则返回2而不是1。 echo $rows
进行检查。