PHP tutorials,a way to getting some thing new in web

Followers

Powered by Blogger.

Wednesday 19 November 2014

Simple Login With PHP

No comments :

Hello Friends,
Today I am going to show you simple login with php session and html form.First we will create html form as follow:



<form method="post" action="index.php" name="form1" id="form1">
      <h2>Login</h2>
      <p> 
        <input type="text" placeholder="Username" name="username" id="username">
      </p>
      <p> 
        <input type="password" placeholder="Password" name="pass" id="pass">
      </p>
      <input type="submit" name="submit1" id="submit1" value="Login" class="button"/>
    </form>

Here on above form there is two fields username and password.User will enter username and password into form and submit it to page.

After submitting form to same page,here see how following code will accept data.

if(isset($_POST['submit1']))
{
$username=addslashes($_POST['username']);
$pass=addslashes($_POST['pass']);
$sel="select * from admin where username='$username' AND password='$pass'";
$res=mysql_query($sel) or die(mysql_error());
$total=mysql_num_rows($res);
if($total > 0)
{
while($rows=mysql_fetch_array($res))
{
session_start();
$_SESSION['ID']=$rows['id'];
   $_SESSION['USERNAME']=$rows['username'];
header("location:dashboard.php");
}

}
}

Please see structure of table admin as follow:








No comments :

Post a Comment