I am quite new to php and I tried to find an answer for this but couldn't, if there is an answer already then I apologize.
I am building a simple website, just a few pages (login, register, home).
On the register form, once the submit button is pressed a PHP script checks if the email used for registration is already in the database, if it is I need to display some feedback to the user.
I have two files, a.php which is really just an html file for the page and b.php which is my script.
I am using session_start() in both of the files and I am displaying a $_SESSION variable in the html page which contains the feedback (i.e "Email already used").
However I keep getting an uninitialized variable warning since when the html page is first opened the $_SESSION variable does not exist yet.
How do I fix this? I do not want to use JS or AJAX at this stage, and would like to keep the files separate. I am aware of what the error means.
This is the code in a.php (the html page)
<p><?php session_start(); echo $_SESSION["message"];?></p>
This is the code in b.php (the script)
if($row){
$_SESSION["message"] = "Email already used";
header( 'Location: register.php' );
exit();
}
Thank you.
EDIT - SOLUTION: Adding
if(isset($_SESSION["message"])){echo $_SESSION["message"];}
fixes the issue.