note 25423 added to function.session-register
| From: | ianp%murphy%yahoo%fr at rack1 dot php dot net | Date: | Mon, 23 Sep 2002 14:04:52 +0000 |
| Subject: | note 25423 added to function.session-register | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37142@lists.php.net to get a copy of this message | ||
The syntax involved in using $_SESSION when passing arrays between a validation page and a display
page (in my case an array of errors) , is not something which is immediately obvious.
If you do the following in,say, validation.php:
if (!session_is_registered("formErrs"))
session_register ("formErrs");
$formErrs=array();
$formErrs ["formName"] = "Error: Name cannot be blank";
you will then need to use the following format to retrieve the values in the main page.
$name="formName";
if (isset($_SESSION["formErrs"]["$name"])) {
echo "We've found " . $_SESSION ["formErrs"] ["$name"])
}
or alternately to just dump the array
foreach ($_SESSION["formErrs"] as $var=>$errText){
Echo "Debug: $var : $errText<br>\n";
}
--
http://www.php.net/manual/en/function.session-register.php
http://master.php.net/manage/user-notes.php?action=edit+25423
http://master.php.net/manage/user-notes.php?action=delete+25423
http://master.php.net/manage/user-notes.php?action=reject+25423