Forum Moderators: coopster
My script takes data out of the $_POST array from a form on the previous page. I make it into a session variable like so:
$_SESSION['idNo'] = $_POST['idNum'];
$idNo = $_SESSION['idNo'];
So far so good; if I look at my session data with
Print_r ($_SESSION);
it appears like so:
[idNo] => 2
I also have links in the page, which allow the user to delete entries from a database according to their id number. The links look like so:
<a href="<?php echo $_SERVER['PHP_SELF'] . '?noticeid=' . $noticeid;?>">Delete condolence notice</a
My problem is, once the link is clicked, and the page reloads, the data in $idNo has disappeared, so
Print_r ($_SESSION);
then appears as:
[idNo] =>
I had thought that putting the data into a session variable would make it persist, but it seems this is not so? I'm thinking that having
$_SESSION['idNo'] = $_POST['idNum'];
execute again is the problem - is the (now empty) $_POST data writing over the previous data in the session variable?
If this is so, can anyone think of a way of circumventing this?
Any help would be greatly appreciated.
You could use something like -
if (![url=http://uk.php.net/manual/en/function.empty.php]empty[/url]($_POST['whatever'])) {
$_SESSION['whatever'] = $_POST['whatever'];
}
<a href="<?php echo $_SERVER['PHP_SELF'] . '?noticeid=' . $noticeid;?>
I'm passing the variables for the reload using GET now, like so:
<a href="<?php echo $_SERVER['PHP_SELF'] . '?noticeid=' . $noticeid&idNo=' . $idNo;?>
I just remembered that I faced exactly the same problem on another site a couple of years ago and fixed it in exactly the same way . . . guess I'm just a bit slow on the uptake . . .
(Quietly resolves not to waste any more of people's time with stupid questions to which she already knows the answer)