Here is my code
why my javascript wouldnot do anything
When user and password matches, I give $hidme=1. otherwise give $hidme=0;
Then in my function (javascript)
I get document.logonform.hidvalue.value,
check it
if the value=1 then action="a.php"
else
action="b.php"
what is the problem?
Thanks
<html>
<?php
if (isset($POST["logon"]))
{
$errors = array();
$password= $POST['txtpassword'];
echo "password filled in is".$password;
$username= $_POST['txtusername'];
echo "user name is ".$username;
echo "logon has been submitted";
if ($username=="") {
$errors[] = 'Please enter user name';
}
if ($password=="") {
$errors[] = 'Please enter your password ';
}
else{
$db = mysql_connect("myserver","user","password");
mysql_select_db("TES3devo",$db);
// get username and password and check the password is correct or not
$sql =" select password from TES_USERS where user_name='$username'";
$result = mysql_query($sql,$db);
$userdata = mysql_fetch_array ($result, MYSQL_ASSOC);
//echo "password in database is ".$userdata['password'];
if ($userdata['password']!="" && (trim($password)==trim($userdata['password'])))
{
$hidme = 1;
//logonform.submit();
echo " you get right".$hidme;
//go to the entry screen
// include "submitdata1a.php";
}
else{
$errors[] ='Please check your password and try again';
}
}
if (count($errors) == 0) {
$hidme = 1;
//include "screen.htm";
//echo " you are logged on";
}
else {
$hidme = 0;
//echo 'Sorry, you have not filled the required fields<br>';
foreach ($errors as $error) {
echo $error . '<br>';
}
}
}
//else{
?>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function displayme()
{
//document.write([document.logonform.hidvalue].value);
if (document.logonform.hidvalue.value=="1"){
alert(" you are welcome");
document.logonform.action="submitdata1a.php";
//logonform.submit();
}
else{
document.logonform.action="logon.php";
}
}
-->
</SCRIPT>
<body bgcolor="#6699CC" text="#000000">
<table border=0 cellspacing=0 cellpadding=0 align="center" width="337" >
<form method="post" name="logonform">
<tr>
<td colspan="4">
<div align="center">
<p><b><font face="Arial, Helvetica, sans-serif">Welcome to CCR Data
Entry System</font></b></p>
<p> </p>
</div>
</td>
</tr>
<tr>
<td colspan="4">
<p><i><font color="#FF80C0"><b>Please log on</b></font></i></p>
<p> </p>
</td>
</tr>
<tr>
<td colspan="1" width="160" ><b>User Name: </b></td>
<td colspan="3" width="232">
<input type="text" name="txtusername">
</td>
</tr>
<tr>
<td colspan="1" width="160"><b>Password:</b></td>
<td colspan="1" width="232">
<input type="password" name="txtpassword" size="30"> <input type="hidden"
name="hidvalue" value="<?php $hidme ?>" size="30">
</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4">
<div align="center">
<input type="Submit" name="logon" value="Log on" onclick="displayme()">
<input type="reset" name="reset" value="Reset">
</div>
</td>
</tr>
</form>
</table>
</body>
<?php
//}
?>
</html>