PHP session variable not being stored
172
My session variables are not being stored.
I tried lot of things likevar_dump
,print_r
and my variables are well printed but not stored.
Here is my code:
<?php
session_start();
require "header.php";
?>
<form action="../Views/index.php?page=createSecteur" method="post">
<div >
<label for="libelle">Libelle : </label>
<input type="text" name="libelle" id="libelle" required value="<?php echo isset($_SESSION['libelle']) ? $_SESSION['libelle'] : "" ?>">
</div>
<button type="submit" name="insert_secteur" id="insert_secteur">Insert secteur</button>
</form>
<?php
if (isset($_POST['insert_secteur'])) {
$_SESSION['libelle'] = $_POST['libelle'];
}
require "footer.php";
?>
UPDATE : My $_POST['libelle'] gave me an error "undefined index"
Answer
Solution:
Try to check if
$_POST['libelle']
exists too.Also try to post to the same page by empty the
action
of your form.This will automatically be the same page when empty.
Answer
Solution:
It does work if you remove action url (If you post to same page):
If you post to other page then post execution must be done on other page.
But if you need to know specific form was sent you can do this: By saving hidden input with key name