Friday 7 February 2014

Login With UserName And Password Using MYSQL And PHP


Here you can find the code please click below
DEMO
Login.php


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Form</title>
</head>
<body>
   
       <form name="form1" method="post" action="db.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>User Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="uname" type="text" ></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="password" ></td>
</tr>
<tr>


<td><input type="submit"  value="Login"></td>
</tr>
<tr>


<td><input type="reset"  value="reset"></td>
</tr>
</table>
</td>
</form>
   
</body>
</html>


Db.php


<?php


$host="localhost";
$username="root";
$password="ubuntu@123456789";
$db_name="practise";
$tbl_name="user";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$uname=$_POST['uname'];
$password=$_POST['password'];
$uname = stripslashes($uname);
$password = stripslashes($password);
$uname = mysql_real_escape_string($uname);
$sql="SELECT * FROM $tbl_name WHERE uname='$uname' and password='$password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
session_register("uname");
session_register("password");
header("location:success.php");
}
else {
echo "Invalid user or Password";
}
?>


Success.php


<?php
session_start();
if(!session_is_registered(uname)){
header("location:./login.php");
}
?>
<?php
session_start();
session_destroy();
?>



<html>
<body>
Login Successful.
</body>
</html>

Databse


db_name:- practise
Table_name:- user


user (table name)


id
uname
password

1
Rituraj kumar
123

2
Robi tomar
r456

3
Shikha chaudhary
shikha123

4
Harshu
354

5
Neeraj
789@neeraj

No comments:

Post a Comment

Printing first 50 Fibonacci numbers Using PHP Program

Fibonacci series is a series of numbers in which each number is the sum of the two preceding numbers. For example. 0 , 1 , 1 , 2 , 3 , 5...