// Login Page In PHP Mysql using 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
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)
{
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>
<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
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)
{
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