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 ?

Check below code:

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

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)

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.";
}
}
?>

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?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.