简体   繁体   中英

How to get the login details of the user if the ID and Password matches with the data in the database?

In this form, the details(id and password) of the user are entered and it checks whether it matches with data present in the database, if it matches it allows the user to log in and it redirects the user to "action.php" page, else it shows the error message. If the user logins successfully, I need to get the remaining details of the user according to the data in the database on "action.php" page. As the database consists of first and last names, Email ID of the user.

This is login form:
        <!DOCTYPE HTML>
    <html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" href="style.css" />
    </head>
    <body>
        <header>
            <nav>
                <div class="main-wrapper">
                    <ul><li><a class="llink" href="home.php">Home</a></li></ul>
                    <div class="nav-login">
                        <form action="" method="POST">
                            <input type="text" name="u_uid" placeholder="Username" />
                            <input type="password" name="u_pwd" placeholder="Password" />
                            <button type="submit" name="submit">Login</button>
                        </form>
                        <a href="signup.php">Sign up</a>
                    </div>
                </div>
            </nav>
        </header>

    <?php
    ob_start();
    include 'phpcode/dbh.php';
    if(isset($_POST['submit'])){
        $db=mysqli_select_db($conn,'loginsystem');
        if(!$db){
            echo "DB  not found <br />".mysqli_error($conn); 
        }

        $id=mysqli_real_escape_string($conn,$_POST['u_uid']);
        $pwd=mysqli_real_escape_string($conn,$_POST['u_pwd']);
        if(!$id==0 || !$pwd==0){
            $sql = "SELECT * FROM users WHERE u_uid='$id'";
            $res = mysqli_query($conn,$sql);
            $rescheck = mysqli_num_rows($res);
            if($rescheck<1){
                echo "<span class='error'>User-name and Password doesn't match</span><br />";
            }else{
                while($row=mysqli_fetch_assoc($res)){
                    $dbid=$row['u_uid'];
                    $dbpwd=$row['u_pwd'];
                }
                if($id == $dbid && $pwd == $dbpwd){
                    session_start();
                        $_SESSION['user_id'] = $row['u_id'];
                        $_SESSION['user_fname'] = $row['u_fname'];
                        $_SESSION['user_lname'] = $row['u_lname'];
                        $_SESSION['user_email'] = $row['u_email'];
                        $_SESSION['user_uid'] = $row['u_uid'];
                        echo "<div class='err-nav'><script type='text/javascript'>window.location.href = 'action.php';</script></div>";
                        exit();
                }else{
                    echo "<div class='err-nav'><span class='error'>Password doesn't matched</span><br /></div>";

                    }
            }

        }else{
            echo "<div class='err-nav'><span class='error'>Cannot be empty</span><br /></div>";

        }
    }
    ?>
if(isset($_POST['submit']))
{
    $userid=$_POST['u_uid'];
    $password=$_POST['u_pwd'];
    $sql="SELECT userid,password where userid='$userid' AND password='$password'";
    $result=mysqli_query($database,$sql);
    if($result->num_rows>0)
    {
    header('location:action.php');
    }
    else
    {
    header('location:login.php');
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM