我无法访问我的管理面板

时间:2016-08-09 08:14:22

标签: php mysql database phpmyadmin

这是我的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');

代码图片:

enter image description here

另一个sql代码图片:

enter image description here

1 个答案:

答案 0 :(得分:1)

1)表示insert query表示password adminadmin。那不是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>";
        }