Login Form With MySql Database
1. Login.html
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<!–
* Created on 21 Dec 2006
* Author : Antony
–>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>Login Page</title>
</head>
<body>
<form action=”login.php” method= “post”>
<br />
<br />
<br />
<br />
<br />
<table bgcolor=”#4C0068″ border=”0″ align=”center” valign=”middle”
cellspacing=”1″ cellpadding=”10″ width=”40%” summary=”pagedesign”>
<tr height=”60%”>
<td align=”center”><br>
<font color=”#FCFC7C” face=”Sans” size=”3″>Username</font></td>
<td align=”center”><br>
<font face=”Sans” size=”4″><input type=”text”
name=”username” size=”21″ maxlength=”40″ /></font></td>
</tr>
<tr height=”80%”>
<td align=”center”><br>
<font color=”#FCFC7C” face=”Sans” size=”3″>Password</font></td>
<td align=”center”><br>
<font face=”Sans” size=”4″><input
type=”password” name=”pwd” size=”21″ maxlength=”40″ /></font></td>
</tr>
<tr>
<td align=”center” colspan=”2″><br>
<font face=”Sans” size=”4″ color=”#FCFC7C”> <input type=”submit”
name=”submit” value=”Login Here” /><br /></font><br></td>
</tr>
</table>
</form>
</body>
</html>
2.login.php
<?php
/*
* Created on 21 Dec 2006
* Author : Antony
*
*/
$uname=”";
//initilaize the mysql user name and oassword
$user=”root”;
$password=”123456″;
//database name
$database=”studentinformation”;
//get the information from login form
$username=$_POST['username'];
$pwd=$_POST['pwd'];
//connect the mysql database
$link=mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die(“Unable to Open Databse”);
//execute the query
$sql = “select * from userdetails”;
$result =mysql_query($sql);
$flag=0;
//retrieve row by row from your table
while($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
//print_r($line[regno]);
if(($username==$line[username]) and ($pwd==$line[password]))
{
if($line[type] == “admin”)
{
$flag=1;
}
else
{
$flag=2;
}
$uname=$line[username];
}
}
if($flag==1)
{
include ‘admin.html’;
//echo “<br><br><center><blink><h2>You are an Admin</blink></h2></center>”;
}
else if ($flag==2)
{
//echo “<br><br><center><h2>You are a User</h2></center>”;
include ‘user.html’;
}
else
{
echo “<br><br><center><h2>You are a not an Authorised User</h2></center>”;
}
mysql_free_result($result);
mysql_close($link);
?>
