I am not able to get my email input even after defining my sessions, please look below:
I have two scripts: The first is is to show the declaration of the session, while the second is to display the session’s value:
First Script:sessionTest1.php
<?php
session_start();
?>
<html>
<head><title>Testing Sessions page 1</title></head>
<body>
<?php
$_SESSION['session_var'] = "testing";
@$_SESSION['session_var2'] = $_POST['email'];
echo "This is a test of the sessions feature.
<form action='sessionTest2.php' method='POST'>
<input type='hidden' name='form_var'
value='testing'>
<input type='text' name='email'>
<input type='submit' value='go to next page'>
</form>";
?>
</body></html>
Please what could be possibly wrong? or what should i do to obtain the entered value for the email and then be able to pass it along to as many pages as possible?
The problem you’ve got here is that you’re trying to assign the value from $_POST[‘email’] to a session var on your first page, sessionTest1.php, but as your form submits to sessionTest2.php the $_POST values will only be available on that second page - not on the first.
The session isn’t being stored in a database. Its just to make some selected data available all through the life time of the user session on the particular site.