FenrisL
FenrisL

Reputation: 287

Handling multiple forms in the same php file

I have a php file that has 3 forms inside and some insert queries and i separate them with if(isset()) so they are not displayed if a variable is not present. I have a problem and i declare a variable after the first form and when i use the second form the variable dissapears and returns as null. Is there a better way to handle this?

Upvotes: 0

Views: 42

Answers (1)

JYoThI
JYoThI

Reputation: 12085

After page load declared variable is not there so use session

if you want first form value you need to store it in session to keep first form value

if(isset($_POST['first_form_submit'])) { $_SESSION['first_form']=$_POST; } 

Note : Don't forgot to start he session_start(); on page very top.

Update 1:

You need email only means do like this

if(isset($_POST['email'])) { $_SESSION['email']=$_POST['email']; } 

Later access it like this $email = $_SESSION['email'];

Upvotes: 1

Related Questions