Create two files.
1. Login.html
2. loginprocess.php
1> Put following code in "Login.html" file.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="post" action="loginprocess.php">
<table width="200" border="1">
<tr>
<td>Username:</td>
<td><input type="text" name="uname" required="required"/></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pwd" required="required" /></td>
</tr>
</table>
<input type="submit" value="SUBMIT" />
</form>
</body>
</html>
2> Put following code in "loginprocess.php" file.
<?php
$uname=$_POST['uname'];
$pwd=$_POST['pwd'];
$con=mysql_connect('localhost','root','');
if(!$con)
{
echo "Connection error".mysql_error();
}
$db=mysql_select_db('test1');
$sql="select * from registration where name='$uname'";
$result=mysql_query($sql,$con);
while($row=mysql_fetch_array($result))
{
$dbpwd=$row['password'];
$dbid=$row['id'];
if($pwd==$dbpwd)
{
session_start();
$_SESSION['id']=$dbid;
?>
<!-- iF sussessfully then Alert-->
<script type="text/javascript">
alert('Successfully Authenticated.');
document.location='profile.php';
</script>
<?php
}
//header('Location:profile.php');
//echo"Login Sussessfully";
else
{
?>
<!------ iF Fail then Alert -->
<script type="text/javascript">
alert('Fail to Authenticate.');
document.location='Login.html';
</script>
<?php
//echo"fail";
}
}
?>
1. Login.html
2. loginprocess.php
1> Put following code in "Login.html" file.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="post" action="loginprocess.php">
<table width="200" border="1">
<tr>
<td>Username:</td>
<td><input type="text" name="uname" required="required"/></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pwd" required="required" /></td>
</tr>
</table>
<input type="submit" value="SUBMIT" />
</form>
</body>
</html>
2> Put following code in "loginprocess.php" file.
<?php
$uname=$_POST['uname'];
$pwd=$_POST['pwd'];
$con=mysql_connect('localhost','root','');
if(!$con)
{
echo "Connection error".mysql_error();
}
$db=mysql_select_db('test1');
$sql="select * from registration where name='$uname'";
$result=mysql_query($sql,$con);
while($row=mysql_fetch_array($result))
{
$dbpwd=$row['password'];
$dbid=$row['id'];
if($pwd==$dbpwd)
{
session_start();
$_SESSION['id']=$dbid;
?>
<!-- iF sussessfully then Alert-->
<script type="text/javascript">
alert('Successfully Authenticated.');
document.location='profile.php';
</script>
<?php
}
//header('Location:profile.php');
//echo"Login Sussessfully";
else
{
?>
<!------ iF Fail then Alert -->
<script type="text/javascript">
alert('Fail to Authenticate.');
document.location='Login.html';
</script>
<?php
//echo"fail";
}
}
?>
0 comments:
Post a Comment