<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