rayzyy
08-31-2014, 09:40 PM
logon.php
<?php
$host="localhost"; // Host name
$username="****"; // Mysql username
$password="*****"; // Mysql password
$db_name="******"; // Database name
$tbl_name="login"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$tellerUserName=$_POST['tellerUserName'];
$tellerPassword=$_POST['tellerPassword'];
$sql="SELECT * FROM $tbl_name WHERE user_name='$tellerUserName' and user_password='$tellerPassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $l_username and $l_password, table row must be 1 row
if($count==1){
// Register $l_username, $l_password and redirect to file "login_success.php"
@session_register("tellerUserName");
@session_register("tellerPassword");
$_SESSION['tellerUserName'] = $_POST['tellerUserName']; // store username
header("location:index.php");
}
else {
header("location:login.php?loginFailed=true&reason=password");
}
?>
Login.php
<script type="text/javascript">
function validateForms()
{
var a=document.getElementById('tellerUserName').value;
var b=document.getElementById('tellerPassword').value;
if (a==null || a=="")
{
alert("Username must be filled out");
document.getElementById('tellerUserName').focus();
return false;
}
if (b==null || b=="")
{
alert("Password must be filled out");
document.getElementById('tellerPassword').focus();
return false;
}
}
</script>
</head>
<body>
<form name="login" method="post" action="logon.php" onSubmit="return validateForms()" id="login" >
<div id="preContainer">
<div class="header">
<div class="logo"></div>
<div class="grayBar2 clear"> </div>
</div>
<?php
$host="localhost"; // Host name
$username="****"; // Mysql username
$password="*****"; // Mysql password
$db_name="******"; // Database name
$tbl_name="login"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$tellerUserName=$_POST['tellerUserName'];
$tellerPassword=$_POST['tellerPassword'];
$sql="SELECT * FROM $tbl_name WHERE user_name='$tellerUserName' and user_password='$tellerPassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $l_username and $l_password, table row must be 1 row
if($count==1){
// Register $l_username, $l_password and redirect to file "login_success.php"
@session_register("tellerUserName");
@session_register("tellerPassword");
$_SESSION['tellerUserName'] = $_POST['tellerUserName']; // store username
header("location:index.php");
}
else {
header("location:login.php?loginFailed=true&reason=password");
}
?>
Login.php
<script type="text/javascript">
function validateForms()
{
var a=document.getElementById('tellerUserName').value;
var b=document.getElementById('tellerPassword').value;
if (a==null || a=="")
{
alert("Username must be filled out");
document.getElementById('tellerUserName').focus();
return false;
}
if (b==null || b=="")
{
alert("Password must be filled out");
document.getElementById('tellerPassword').focus();
return false;
}
}
</script>
</head>
<body>
<form name="login" method="post" action="logon.php" onSubmit="return validateForms()" id="login" >
<div id="preContainer">
<div class="header">
<div class="logo"></div>
<div class="grayBar2 clear"> </div>
</div>