(1)first create file index.html
<form action="login.php" method="post">
<span class="loginText">User name:</span><br>
<input name="username" type="TEXT"><br>
<span class="loginText">Password:</span><br>
<input name="Password" type="PASSWORD">
<br>
<span class="loginText">login as user: <i>demo</i><br>with password: <i>anahaw</i></span>
</td>
</tr>
<tr>
<td align="right"><input value="submit" name="SubmitUser" type="submit"></td>
</form>
(2)create login.php file
<?php
$username=$_POST['username'];
$password=$_POST['Password'];
$con=mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("payroll",$con);
$sql="select username,password from login where username='$username' AND password='$password'";
$result=mysql_query($sql) or die(mysql_error());
$num=mysql_num_rows($result) or die(mysql_error());
if($num>0)
{
session_start();
$_SESSION['username']=$username;
header("Location:welcome.php");
}
else
{
echo "invalid login";
}
?>
No comments:
Post a Comment