How to Create a Login Form - Php

How to create a login form using php?

Snippet Code

Rate this page :
  [ 0 votes]

Use the below code to create a login form for your web page using PHP code and MySQL database. If the given username and password both are correct then output will be: Login Successful!!. If any one of the field or both are incorrect then the output will be: Login Failed!!.

<?php error_reporting(0); $link = mysql_connect("localhost", "root", ""); $conn=mysql_select_db('testdb',$link); $user = $_POST['username']; $password = $_POST['password']; if(!empty($_POST['username'])) { $query = mysql_query("SELECT * FROM login") or die(mysql_error()); while ($row=mysql_fetch_array($query)) { $uname = $row['username']; $pass = $row['password']; if($uname==$user amp&$pass==$password) { $msg = "Login Successful!!"; } else { $msg = "Login Failed!!"; } } } mysql_close(); ?> <form method="POST" action=""> User Name : <input type="text" name="username" size="20"></br></br> Password : <input type="password" name="password" size="20"></br></br> <input id="button" type="submit" name="submit" value="Log-In"></br> <div id='msg'><?php echo $msg;?></div> </form>


Ask Questions

Ask Question