检查用户的数据库(phpmyadmin)并允许该用户访问该页面

时间:2016-02-17 19:51:38

标签: php mysql login

**当有人登录详细信息并且如果用户在该数据库中时,我如何检查数据库,那么它将允许他/她访问下一页,否则它将回显错误?

            <form action="profile_student.php" method="post" enctype="multipart/form-data">
                <p> <input type="text" name="user_login" placeholder="Email"  required/></p>
                <p><input type="password" name="user_pass" placeholder="Password" required/> </p>
                <input type="submit" name="login_submit" value="Log In"/> 
            </form>
        </div>

***

**<?php
//log in variables
$login_user = @strip_tags($_POST['user_login']);
$login_password = @strip_tags($_POST['user_pass']);
$login_submit = ($_POST['login_submit']);



if ($login_submit){
    $login_query = mysqli_query ($connect,"SELECT * FROM users WHERE e-mail = '$login_user' AND password = '$login_password'");
    // mae the query, now we check if the user exists
    $check_user = mysqli_num_rows ($login_query);
    if ($check_user == 1) {
        // if there is a valid user in the db, if the results returned are one row, then log the user in, otherwise error


        // we need to create to session variables for  user so the user can log in, save details etc.
        $_SESSION["user_login"]=$login_submit;
        header("Location: profile_student.php");
        echo "logged in";
    }
?>**

0 个答案:

没有答案