I have two pages apply.php and registration.php.
In registration.php, i have
if(isset($_POST['submitted'])){
//validation part
$form_error ='';
if(!$fullname){
$form_error.= "Enter full name<br />";
header('Location: apply.php');
And in apply.php, I display an error message if an error happened:
<p><?php if(isset($form_error))echo $form_error?></p>
<form action="registration.php" method="post">
<label for="fullname">Fullname</label>
<input type="text" name="fullname" />
Why I am not getting echoed error message “Enter full name” in apply.php ?
You’re not getting it because apply.php doesn’t know about $form_error – it was initialised in registration.php, but not in apply.php.
You could do the following:
Then you could access that on apply.php.
Alternatively, you could also pass the error through the header (via GET):
And access it like this in apply.php: