When using this code to try an show an error, the page redirects to myaccount, but should only redirect there if the required field has been completed, for example;
error message appears if birth_country is not chosen
if(empty($birth_country))
{
$err[] = "ERROR - Enter Birth Country";
header("Location: personal.php?msg=$err[0]");
}
but if it is chosen, should redirect to…
header("location: myaccount.php?id=" . $_SESSION['user_id']. "");
exit();
However it always goes to myaccount no matter what
Thanks
Like Frits says, you will have to print out the error to the screen if you want it to be seen; however, you can not print out any HTML before a
headeror theheaderwon’t work. If you want to print the error on the redirecting page then I would suggest putting the error message in a$_SESSIONcookie, then call andechothat cookie/variable on the redirecting page. But by doing this, you will need to usephp session_start()at the top of the question page and the top of your redirect page in order to use the$_SESSIONvariablesAlso, your second
headerShould look like this:
By using the double quotes, you don’t need to add the
$_SESSION[]tag, then add blank""at the end.