这是我的PHP代码:
if(isset($_POST['admlogin']))
{
$u = $_POST['admname'];
$pass = $_POST['admpass'];
$_SESSION['admin']=$u;
$p = md5($pass);
$q = "SELECT * FROM admin WHERE user='$u' AND pass='$p'";
$cq = mysqli_query($con,$q);
$ret = mysqli_num_rows($cq);
if($ret == true)
{
header('location:backend.php');
}
else
{
echo "<script>alert('Wrong Login Details, Try Again!')</script>";
}
这是我的sql代码:
INSERT INTO admin (id, user, pass ) VALUES
(1, 'admin', 'admin'),
(2, 'friends', 'friends');
代码图片:
另一个sql代码图片:
答案 0 :(得分:1)
1)表示insert query
表示password
admin
为admin
。那不是md5
那么为什么你在比较时md5
password
。
2)从md5
移除$pass
,因为您尚未在md5
中保存password
database
。并添加mysqli_error()
function
以查看任何errors
if(isset($_POST['admlogin']))
{
$u = $_POST['admname'];
$pass = $_POST['admpass'];
$_SESSION['admin']=$u;
// $p = md5($pass); remove this or save password with md5 in db
$p = $pass;
$q = "SELECT * FROM admin WHERE user='$u' AND pass='$p'";
$cq = mysqli_query($con,$q) or die(mysqli_error($con));
$ret = mysqli_num_rows($cq);
if($ret == true)
{
header('location:backend.php');
}
else
{
echo "<script>alert('Wrong Login Details, Try Again!')</script>";
}