34 thoughts on “how to create login page in php with mysql

  1. if you're trying to do all this through command line in linux, you need to change mysqli_connect to another user. Root is blocked and it won't work. Create another user in sql and give it all privilleges

  2. dear sir i have a create a problem.
    that login page
    .
    my database name and table name defint but login page show EORRE messages.
    Username of Password is Invalid.
    pl. reply soon.
    pl. check my code

    <?php
    $error=''; //Variable to Store error message;
    if(isset($_POST['submit'])){
    if(empty($_POST['username']) || empty($_POST['password'])){
    $error = "Username or Password is Invalid";
    }
    else
    {
    //Define $username and $password
    $user=$_POST['username'];
    $pass=$_POST['password'];
    //Establishing Connection with server by passing server_name, user_id and pass as a patameter
    $conn = mysqli_connect("localhost", "luckyprajapat", "");
    //Selecting Database
    $db = mysqli_select_db($conn, "jaishree");
    //sql query to fetch information of registerd user and finds user match.
    $query = mysqli_query($conn, "SELECT * FROM lokesh WHERE password='$password' AND username='$username'");

    $rows = mysqli_num_rows($query);
    if($rows == 1){
    header("Location: shree.php"); // Redirecting to other page
    }
    else
    {
    $error = "Username of Password is Invalid";
    }
    mysqli_close($conn); // Closing connection
    }
    }

    ?>

    my sql filed
    ID
    username
    password
    email

    my sql con.

    database name jaishree
    table name lokesh

Leave a Reply to Dilaa Sathana Cancel reply

Your email address will not be published. Required fields are marked *