Suggested articles for you:

9 thoughts on “PHP Login Form using MySQL


    hello sir, i need to make a website with login page.which type of validation should be best for me ?i have tried js validation but at the background in the pagesource somebody might find my id and password.please help me sir.

    1. Ravi Bandakkanavar Post author

      Hi Aloka,

      Yes. Using javascript would expose your values. You can overcome this by using database validation.
      I have mentioned following chunk of code in Login.php.

      if ($_SERVER['REQUEST_METHOD'] == 'POST')
      if (empty($_POST['username']) || empty($_POST['password'])) //This is the way to validate inputs using PHP code but here we are using javascript validations so it is not necessary
      echo "Please enter the correct Username and Password";
      //header("location: LoginForm.php");//You will be sent to Login.php for re-login

      The database validation would consume little more time as compared to JS validations but in the case of JS, it would increase the web page size. You need to choose based on your requirement.

      If you still want to go for Javascript validations, you can use document.getElementById() to read from fields and have the code at a separate place by giving a reference in the head.

      My suggestion to you: go for certain frameworks which will reduce a lot of your work. some famous ones are, etc.

      Keep us updated with what you choose and about your website and Good Luck :)

  2. Ravi Bandakkanavar Post author

    Updated the Login application with PHP 7.0 supported methods as many methods like mysql_real_escape_string(), mysql_query(), mysql_num_rows(), mysql_connect(), mysql_select_db(), mysql_close() were depricated in PHP 5 and removed from the latest version of PHP i.e. PHP 7.0.

  3. K.Sangavi

    Hi Sir,
    How to run php in xamp. How to connect html and sql for online library renewal system for mini project.

    1. Ravi Bandakkanavar Post author

      Hi Sangavi,

      Please go through following post to understand on html or php files location and also to create SQL database.
      Xamp and wamp both are almost same.

  4. Dinesh

    can you give me an idea for my mini project so that it will be helpful for my career.

  5. Kiran

    Good post sir. Its easy to unserstand.
    Logic to find number of logged in users is nice.
    Thank you sir.


Did it help? Comment here..