0

i'm just very new in php & its my 1st post here.. having a small problem to pass the login error msg to LOGIN.PHP from check login page.

here is the code of checklogin.php file:

if($count==1){

// Register $myusername, $mypassword and redirect to file "welcome.php"
session_register("myusername");
session_register("mypassword");
header("location:welcome.php");
}
else {
$msg = urlencode("Invalid Login. Please try again with correct user email and password. ");
header("Location: login.php?msg=$msg");
}

And here is the login.php file where want to show the error mssg:

<?php
if (isset($GET['msg'])) {
$err = mysql_real_escape_string($_GET['msg']);
echo $err;
}
?>

Anybody help please where to change or add the code ?

4
Contributors
5
Replies
7
Views
4 Years
Discussion Span
Last Post by doha786
1

Check below code:

<?php
if ($GET['msg']!="") {
$err = urldecode($_GET['msg']);
echo $err;
}
?>
0

Thanks for your reply.. i had tried above code too but no ouput. Its passing the msg but not showing. (Not found any error also)

1

change get variable in header

    if($count==1){
    // Register $myusername, $mypassword and redirect to file "welcome.php"
    session_register("myusername");
    session_register("mypassword");
    header("location:welcome.php");
    }
    else {
    $msg = urlencode("Invalid Login. Please try again with correct user email and password. ");
    header("Location: login.php?error=1");
    }

And your login.php

<?php
if (isset($GET['error'])) {
if($_get['error']==1)
{
echo "Invalid Login. Please try again with correct user email and password.";
}
}
?>
2

The problem is with the $_GET['error'] variable - in one place it is $_GET in the next palce it is $GET without the underscore. You need the underscore in both instances, $GET is not the same as $_GET. Also you can send the message via the URL (the get method), but as Daniel shows the message can be given on the login page as presumably there is only one error message and therefore no need to carry it from one page to another?

0

Really thanks Adam... the problem was in $GET without the underscore & its working now.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.