I am using a code from the book 'PHP & MySQL for Dynamic Websites' by Larry Ullman (Visual QuickPro Guide) for my login page.
I have followed the code for the queries without any problem, but it sets the form action for the username / password form to the following ;
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
When I run this form it comes up with error HTTP 404 File Not Found.
I understand that the form action basically send the user to a page location, and I have not got this page located on my server, so I am getting the error message, but I don't understand what file I am supposed to be saving, where to save it, and what code needs to be on this file to handle to form and take the user to the page I have specified in the header ("location: ......") part of my code.
The full code is shown below......
any ideas? thanks
<?php
if (isset($_POST['submit']))
// Check if the form has been submitted
{
require_once ('../mysql_connect.php');
//connect to the database
if (empty($POST['submit']))
// validate the username
{ $username = FALSE;
echo '<p><font color="red"> You forgot to enter your username</font></p>';
}
else
{
$username = escape_data($POST['username']);
}
if (empty($POST['password'])) // validate the password
{ $password = FALSE;
echo '<p><font color="red"> You forgot to enter your password</font></p>';
}
else
{
$password = escape_data($POST['password']);
}
if ($username && $password) // everything is OK
{ // query the database
$query = "SELECT CLogIn FROM tblUser
WHERE CLogIn='$username'
AND CPass=PASSWORD('$password')";
$result = @($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
if ($row) // username and password match database records
{ // start the session, register the values, and redirect
$SESSION['username'] = $row[1];
$SESSION['user_id'] = $row[0];
header ("Location: [url]http://[/url]" . $SERVER['HTTP_HOST'] . dirname($SERVER['PHP_SELF'] . "/equipment.php");
exit();
}
else // no match was made
{
echo '<p><font color="red">The Username and Password you entered do not match those on file.</font></p>';
}
}
else // if everything wasn't OK
{
echo '<p><font color="red">Please try again</font></p>';
}
}
?>
<?php
include ('header.php');
?>
<br>
<h1><font face="Arial, Helvetica, sans-serif">Login</font></h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend><font face="Arial, Helvetica, sans-serif">Please Enter Your Information Below;</font></legend>
<p><font face="Arial, Helvetica, sans-serif" size="3"> <b>Username:</b>
<input type="text" name="username" size="30" maxlength="60" value="<?php if(isset($POST['username'])) echo $POST['username']; ?>" />
</font></p>
<p><font face="Arial, Helvetica, sans-serif" size="3"> <b>Password:</b>
<input type="password" name="password" size="30" maxlength="60" />
</font></p><br>
</fieldset>
<div align="center"> <input type="submit" name="submit" value="Submit" /></div>
</form>