meWantToLearn meWantToLearn - 8 months ago 39
HTML Question

session gets lost after form submit

When a user links to link it redirects to edit.php - here's an example:

In edit.php, I use

to store the value in a session. The value is stored in
but when the form on the same page is submitted
echo $_session['user']
displays nothing - how can I make it display the value?.

$_session['user']=$_GET['id']; // I use _GET to store the value in session
if( isset($_POST['submit'])) {
echo $_session['user'];


<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="formI2D" enctype="multipart/form-data" id="formI2D" />


It's because you're redeclaring your $_SESSION['user'] even when it's a POST (I think).

You can fix this by adding ?id=$_GET['id'] in you form's action, or by wrapping your $_SESSION initialisation like that:

if (isset($_GET['id'])) {

Also, you should use uppercase for php global arrays ($_POST, $_COOKIE, $_SESSION etc)