Friday 24 June 2016

How to create Login Page with Login process?

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";
}
}
?>


To download code Click Here.

For more Interesting, Useful Article & codes visit IT New Code.

Ankit Shah PHP Expert

IT New Code suggest a solution for your problem related to coding, Specially .PHP, Wordpress, WooCommerce, Magento, HTML and CSS. Visit Our website for Information.

0 comments:

Post a Comment

 

Copyright @ 2016 IT New Code | Developing Code | Designing Code.

Designed by: Ankit Shah