There is a login page (login.php)which has username, password and submit button, firstly, this page checks a special variable($error_msg)if its empty or not
- if $error_msg is empty,the PHP code does not do anything
- if $error_msg is not empty, the PHP code displays the value of $error_msg
when Login.php is sent to the browser for the first time, it should not display any error message
the form is submitted to Auth_CityForm.php when the user presses the submit button.
Auth_CityForm.php return 2 responses, if the credentials(the username and password are hard-coded values) are invalid, the page "forwards" the response to Login.php, as follows:
1. set the error message variable $error_msg to the value:
"Invalid credentials.
Please enter valid credentials and submit them again."
2. include the Login.php file
If the credentials are valid,the page displays
1. the text "Hello ", followed by the name of the user, as entered by
the user and
2. a form called city_name, which has
1. one text input field, where the user enters a city name
2. one submit button, whose name is SubmitCityName.
The code that I have has errors and I don't know what to do next?
Here's the code for both Login.php and Auth_CityForm.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login</title>
</head>
<body>
<h1> Login Details </h1>
<?php if (!empty($error_message)) { ?>
<p class="error"><?php echo $error_message; ?></p>
<?php } ?>
<form action="Auth_CityForm.php" method="post">
<label> Username : </label>
<input type = "text" name = "username" /> </br>
<label> Password : </label>
<input type = "text" name = "password" /> </br>
</br>
<input type = "submit" value = "SubmitCredentials"/> </br>
</form>
</body>
</html>
<?php
$Username = $_POST['username'];
$Password = $_POST['password'];
//validate username entry
if (empty($Username))
{
$error_msg = "Invalid credentials. Please enter valid credentials and submit them again.";
}
else if($Username == '3020ta' AND $Password == '3020')
{
echo "Hello, 3020ta";
}
else if ($Username == 'asdf' AND $Password == '')
{
echo "Hello, asdf";
}
// set error message to empty string if no invalid entries
else
{
$error_msg = ' ';
}
//if an error message exsts go to login.php
if ($error_msg != '')
{
include('Login.php');
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body>
<h1> Login Details </h1>
<label>Username : </label>
<span> <?php echo Username; ?></span><br/>
<label>Password : </label>
<span> <?php echo Password; ?></span><br/>
</body>
</html>

New Topic/Question
Reply



MultiQuote







|