Tuesday 9 July 2013

Login Page In PHP Mysql using sessions and java script

// Login Page In PHP Mysql using sessions and java script

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
function uservalid()
{
var name = document.form1.username.value;
if(name =="")
{
alert("Please Enter Name");
document.form1.focus();
return false;
}
}</script>
<?php
session_start();
if(isset($_POST['sub']))
{
$username=$_POST['username'];
$password=$_POST['password'];
$con=mysql_connect("localhost", "root", "")or die("cannot connect");
  $db=mysql_select_db("bnr");
  $sql="SELECT * FROM login
WHERE name='$username' and password='$password'";
  $query=mysql_query("$sql");
  $count=mysql_num_rows($query);
   
    if($count!=0)
{
//session_register("name");
     // session_register("password");


$_SESSION['out']=true;
echo "Login Success";

}
else
echo "<font color='#FF0000'>invalid</font>";
}
?>

</head>
<body>

<form action="" method="post" id="form1" name="form1" enctype="multipart/form-data" onsubmit="return uservalid()">
username:<input type="text" name="username" id="username" />
<br />
password:<input type="password" name="password" id="password" />
<br />
<input type="submit" value="login" name="sub" />
</form>
</body>
</html>

No comments:

Post a Comment