PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I want to check the username and password i enter in to the form.
The problem i face is, though i submit the form with wrong password 'success_page.php' get processed.
The problem starts right here. Notice the use of a single equal sign. What you are checking, is if $_REQUEST['username'] is successfully set to the variable of $username. I think what you intend to do, is check if $_REQUEST['username'] is equal to $username. In that case, you need to use 2 equal signs "==" to make it a comparative operater, rather than an assignment operator.
You should also not use the $_REQUEST superglobal. Instead, if you expect the data to come from a form POST, then use $_POST. If you expect the data to come from the url querystring, then use $_GET. If you expect the data to come from a cookie, use $_COOKIE.
On changing the single '=' in to '==', it is working fine.
Need help on two more things.
1. My form display the message of "Login failed!", before submitting the values.
2. How to use SESSION concept here. That is., i want to display the name of the user who has entered in to the page.
<?php
$username = "jawahar";
$password = "welcome";
// This check is pointless since you have explicitly set these values above
if(isset($username) && isset($password))
{
// Here you're checking if the form has been submitted and the username/password match
if(($username == $_REQUEST['username']) && ($password == $_REQUEST['password']))
{
header('location:success_page.php');
}
// Fail if they don't match
// This will also fail if the form hasn't been submitted
else
{
$msg = "Login failed!";
}
}
// This will never be executed.
else
{
$username = "";
$password = "";
}
?>
<?php
$username = "jawahar";
$password = "welcome";
// Check if the form has been submitted
if (!empty($_POST))
{
// Now check that the form values match the values above
if(($username == $_POST['username']) && ($password == $_POST['password']))
{
header('location:success_page.php');
}
// Fail if they don't match
else
{
$msg = "Login failed!";
}
}
?>
phpjawahar wrote:2. How to use SESSION concept here. That is., i want to display the name of the user who has entered in to the page.