How to Create A Simple Login Form in PHP & MySQLi Tutorial




How to Create A Simple Login Form in PHP & MySQLi Tutorial. Download Source Code …

Original source


43 responses to “How to Create A Simple Login Form in PHP & MySQLi Tutorial”

  1. thank you very much. i was able to do this successfully. i am a newbie and wannabee programmer. i recommend this to those who are starting to try php and mysql/mysqli. this is build using the current php7 functions.

    thank you!

  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

  3. Good day,
    Everything is done yet, nothing happens,
    is it really like this?
    $conn = mysqli_connect("localhost", "root", "");
    is my servername correct? or my root? and the blank quotation?
    it just accepts the input and refreshes the page

  4. Me sale este error :
    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.
    Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

    alguien sabe que significa

  5. if we have multiple username and password
    how can we check. here u just stored a single username and password and in query just assigned if (row ==1)..tell me if i have multiple data how i should modify this

  6. This is not secure you need to hash the passwords do not use md5 use one of following

    Argon2 (requires PHP extension)
    Scrypt (requires PHP extension)
    Bcrypt

    one thing to remember is that all have pros and cons

  7. Hi,
    When i type the wrong username or password it say Invalid Username or Password, which is expected. However, I type the correct username and password, it doesn't redirect to welcome.php and refreshes to the same login page instead. What could i have missed?

  8. hi!

    when I try to log me with a user I created, gives this error:

    "Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:xampphtdocsRT_SITEloginserv.php on line 19"

    Any idea? thank you

Leave a Reply