I have the error:
Notice: Undefined variable: back in C:\Program Files\Apache Group\Apache2\htdocs\main.php on line 3
Notice: Undefined variable: back in C:\Program Files\Apache Group\Apache2\htdocs\main.php on line 7
Notice: Undefined variable: back in C:\Program Files\Apache Group\Apache2\htdocs\main.php on line 8
which refers to the variable $back
Here are my codes
main.php:
<html>
<head>
<title>Employee Overtime System Login</title>
</head>
<body bgcolor="#663366" link="#0000FF" text="#FFCCFF" alink="#FF0000" vlink="#FF00FF">
<p>   </p>
<p>   </p>
<p>   </p>
<?php
// if successful login, display here
if ($back == 2) {
echo "Successful Login";
} else {
// if empty fields or failure
if ($back == 1) { echo "All fields required"; }
else if ($back == 3) { echo "Login Failure, Try again"; }
}
?>
<p align="center"><font size="7" style="Arial Black"> Supervisor EOT Login</font></p>
<form name="frmLogin" method="post" >
<table border="4" bgcolor="#FFFFFF" align="center" cellpadding="0" width="51%" bordercolor="#663399">
<tr>
<td>
<table width="100%" height="225" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#66FFFF">
<tr><td bgcolor="663399">
<p> </p>
<table width="84%" height="70" bgcolor="#663399" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="34%" height="37%"><div align="left">
<font size="4"> Employee ID :</font></div>
</td>
<td width= "60%"><input type="text" tabindex="0" name="EmpID">
</td>
</tr>
<tr>
<td height="100%"> <font size="4"> Password :</font></td>
<td width="60%"> <input type="password" tabindex="" name="Password"><td>
</tr>
</table>
<p align="center">
<input align="center" name="login" tabindex="" type="submit" id="btnLogin" value="Login" style="font-family:verdana,arial,helvetica; font-size:10pt; height:25; width:140; background:#99CCFF; border:2 solid #663366; cursor:hand">
</p>
</td></tr>
</table>
</td></tr>
</table>
</form>
</body>
</html>
and my test2.php
<?php
include("main.php");
$db_host="localhost";
$mysql_database="dbtest01";
$link = mysql_connect("localhost") or die("Unable connect to MySQL Server");
mysql_select_db($mysql_database, $link) or die("Unable to select database");
// $login comes from your form submit button name
if (isset($btnLogin)) {
if (empty($EmpID) || empty($Password)) {
// if empty fields
header("Location: main.php?back=1");
} else {
$sql = mysql_query("SELECT * FROM SUPERVISOR WHERE Supervisor_ID='$EmpID' AND Password='$password' ")
or die(mysql_error());
if (mysql_num_rows($sql)) {
// if you want to have a cookie set
//$cookieName = "TEMP";
//setCookie($cookieName,'1',time()+(3600),'/','',0);
// if success
header("Location: main.php?back=2");
} else {
// if failure
header("Location: main.php?back=3");
}
}
}
?>
How should I resolve the problem?