In my website files, I have 3 files, a file that has some basic PHP code such as collecting user data, and to make the code organized, I include the templates and the form files instead of writing their code in the same page.
So, I have the form included after the templates file. Now, after submitting the form, I wanna show the error code (if exists) but I cannot send it to the first page (that is included before it) because it will say Undefined variable
. and I tried sending the variable using $_SESSION
but it wasn't a good idea because even after refreshing the page, the error will stay.
So, I decided to make it with GET
requests. (ex: http://website.com/form?status=failed&error=gender).
And the code that gets the GET
value is:
$status = $_GET['status'];
$error = $_GET['error'];
$error1 = "You have to choose the gender.";
if ($status == "failed"){
if ($error == "gender"){
$message = $error1;
echo '<div class="message">'.$message.'</div>';
}
} else {
echo '<h4 class="tab-info">Complete these steps in order to get posts related to your interests.</h4>';
}
In case that $status
or $error
were empty (http://website.com/form) not submitted yet, it will give the following error: Undefined index: status in **path**
, how can this be solved?
Thanks in advance.