Reputation: 337
<?php session_start();
ob_start();
include("config.php");
$user=$_POST['fname'];
$pass=$_POST['password'];
$result=mysql_query("SELECT * FROM user_detail WHERE password='$pass' AND email='$user'") or die("Couldn't query the user-database.");
$row=mysql_fetch_array($result);
if(!$result)
{
die(mysql_error());
}
$count=mysql_num_rows($result);
if($count==1)
{
$_SESSION['login_user']=$user;
header('Location:'.$_SERVER['HTTP_REFERER']);
}
else if($pass=="" || $user=="")
{
header('Location:'.$_SERVER['HTTP_REFERER']);
}
else
{
header('Location:'.$_SERVER['HTTP_REFERER']);
}
?>
Here if any user is not giving username or password, it's redirecting to the previous page according to the code..
But i want to add something in the header location like this
header('location:index.php?msg=incorect1');
How can i add this in the code
header('Location:'.$_SERVER['HTTP_REFERER']);
Upvotes: 1
Views: 83
Reputation: 1229
header('Location:'.$_SERVER['HTTP_REFERER']."?msg=incorect1");
note: this only works if the referring page is not using the GET already.
Alternatively, you can set a $_SESSION variable which is read by the page. This does however require you to use sessions throughout the site, wherever you offer the login option.
Upvotes: 1
Reputation: 4331
Set session for messages.either success or errors like this :
$_SESSION['msg'] = "Sorry some error";
or
$_SESSION['msg'] = "Successfully saved";
Then use redirect like you did.
header('Location:'.$_SERVER['HTTP_REFERER']);
And on the previous page just echo $_SESSION['msg'];
Upvotes: 0