Echo Error Message for Incorrect Login
Hi,
I am having default.php and checklogin.php page.
When i login from default.php, it checks for correct login from checklogin .php.
When the login is correct, checklogin.php redirects to other page.
But if it is wrong, the page redirects to default.php page and here i want to echo as Incorrect Login.
I am already having Javascript Validation in default.php.
Re: Echo Error Message for Incorrect Login
you can either:
- set a query string variable
- set a cookie
- or set a session
that says the login was incorrect. then, check if this query string/cookie/session exists on your main page and display an error message if so.
Re: Echo Error Message for Incorrect Login
Ya Thankyou, which is the best one for displaying more errors..
Re: Echo Error Message for Incorrect Login
it doesn't matter, that's why I gave you three different options.
Re: Echo Error Message for Incorrect Login
Hi,
I used the sessions method, but it has some errors. Each and every time when the page loads the "Invalid Login" error message is displayed, even when the page is not posted to check the login.
checklogin.php coding
Code:
if($hash != $userdata['userpwd'])
{
$_SESSION['ErrorLogin'] = "Invalid Login";
header('Location: ../default.php');
//echo "Fails";
}
login.php coding
Code:
<?PHP
session_start();
if (isset($_SESSION['ErrorLogin']))
{
$error = $_SESSION['ErrorLogin'];
echo "$error";
}
Re: Echo Error Message for Incorrect Login
After you print it, you need to clear the session variable, otherwise it will stay set for as long as the session exists.
Code:
<?php
session_start();
if (isset($_SESSION['ErrorLogin']))
{
$error = $_SESSION['ErrorLogin'];
echo "$error";
unset($_SESSION['ErrorLogin']);
}