Hello All,
I have been working with a part of my project today, and I have been stuck with what might be something simple---I really don't know...
I have a login form, which will accept a username, password, and department. Upon logging in, control will set those items as session variables.
When I test this script, everything works fine...(Error checking works, it connects to the database and authenticates, and it produces the right message).
When a user is logged in, they have access to the drop-down box, which will allow them to link to 5 different pages...Problem is, when I choose the option and click 'submit', the page simply reloads itself. When I click 'Submit' a second time, it directs to the correct page.
Why in the world do I have to click 'Submit' two times???? This is a real project that will be in use, and I need all the help I am able to get!!
Thanks so much!!!
Mike
<?php
// Start the session
session_start();
// If a session is not registered, execute this code
if ( !session_is_registered('username') or !session_is_registered('password') or !session_is_registered('department'))
{
// No session variables are registered, so register them
session_register('username');
session_register('password');
session_register('department');
}
// Proceed to the next if statement
if ($_POST['username'] <> "" or $_POST['password'] <> "" or $_POST['department'] <> "")
{
// The log-in form has been completed, because all the fields at least equal something
// Set the username and password to be from the form
$username = $HTTP_POST_VARS['username'];
$password = $HTTP_POST_VARS['password'];
$department = $HTTP_POST_VARS['department'];
}
// Proceed to the next if statement
if ($_SESSION['username'] <> "" or $_SESSION['password'] <> "" or $_SESSION['department'] <> "")
{
// Session equals something, so use these values for the fields
$username = $_SESSION['username'];
$password = $_SESSION['password'];
$department = $_SESSION['department'];
}
else
{
header("Location:login.htm");
}
//Error check the username field
if (empty($_SESSION[username]))
{
$msg = "Invalid...";
}
// Error check the password field
elseif (empty($_SESSION[password]))
{
$msg = "Invalid...";
}
else
{
// Connect to the database...
if ($num != 0)
{
$msg = "<table width=65% cellspacing=0 cellpadding=0 border=0 bgcolor='#F7F7F7'>
<tr><td align='top'><font face='Arial' color='#4d50a3' size='+1'><center>
Welcome,<font face='Arial' color='black'> $_SESSION[username]</font>, you are now logged in!</font></center></td>
</tr>
<tr><td><center><b>
<font face='Arial' color='black' size='2'>Choose an option to manage your department.</font>
</b></center></td></tr>
<tr><td><center><font size='-5' face='Arial'><a href='help.php'>HELP</a></font></center></td></tr>
<tr><td> </td></tr>
<tr><td><center>
<form action='$location' method='POST'>
<select name= location>
<option value='ap.htm'>Add an employee profile</option>
<option value='up_pf.php'>Update an existing employee profile</option>
<option value='del_pf.php'>Delete existing employee profiles</option>
<option value='cr_rpt.php'>Create a custom department report</option>
<option value='import.php'>Import an MS spreadsheet</option>
</select>
<input type='submit' name='submit' value='Submit'>
</form>
</center>
</td></tr>
<tr><td> </td></tr>
<tr><td><center><font face='Arial' size='+1' color='#4D50A3'>Click <a href='tyalo.php'>HERE</a> to log-out.</center></td></tr>
</table>
";
}
else
{
$msg = "Error...";
}
}
?>
<!--After error-checking and data-validation on all fields, a message will be generated, and printed in the main body