473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

$_SESSION Array

Tom
A small problem that has me kinda baffled. This is the situation:

I've set up a self-submitting form FORM.PHP. Once the inputs are
validated, the info gets put in SESSION variables and the script
redirects the user to a review form REVIEW.PHP which displays the info
the user has input and allows them to edit or submit. At the top of
that page, I have the following code:

--- start code ---

foreach ($_SESSION as $key=>$submission) {
if ( empty($submission) || ($submission == "") || (strlen($submission)
== 0) ) {
$DISPLAY[$key] = "« BLANK »";
}
else {
$DISPLAY[$key] = $submission;
}
}
extract($DISPLAY);

--- end code ---

The form then displays the info now extracted from the $DISPLAY array.

By creating a new array $DISPLAY for the $_SESSION variables, the idea
is that this page will indicate the optional fields where the user
didn't input data with the string, "BLANK", without changing data in
the $_SESSION array. At the bottom, there is an edit button which will
take a user back to the original form where the form will be
repopulated with the $_SESSION data.

The problem I'm having is that the blank $_SESSION variables are being
overwritten with the "BLANK" string that's only meant to appear in the
review form. Not a huge problem, but I can't figure out why it is
happening.

Any ideas? I've scoured my code. There's nothing that deliberately
overwrites info in the $_SESSION array on the review page. All I can
figure is it must have something to do with the way FOREACH operates.
Any help is appreciated,

Tom

Jul 17 '05 #1
4 3085
Tom wrote:
A small problem that has me kinda baffled. This is the situation:

I've set up a self-submitting form FORM.PHP. Once the inputs are
validated, the info gets put in SESSION variables and the script
redirects the user to a review form REVIEW.PHP which displays the info the user has input and allows them to edit or submit. At the top of
that page, I have the following code:

<snip>

I don't know, why you have to mess up with session for form. Here is
my old version of form processing script <
http://groups.google.com/gr*******************************************@post ing.google.com>,
which may be helpful sometimes.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #2
"Tom" <kl******@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
A small problem that has me kinda baffled. This is the situation:

I've set up a self-submitting form FORM.PHP. Once the inputs are
validated, the info gets put in SESSION variables and the script
redirects the user to a review form REVIEW.PHP which displays the info
the user has input and allows them to edit or submit. At the top of
that page, I have the following code:

--- start code ---

foreach ($_SESSION as $key=>$submission) {
if ( empty($submission) || ($submission == "") || (strlen($submission)
== 0) ) {
$DISPLAY[$key] = "&laquo; BLANK &raquo;";
}
else {
$DISPLAY[$key] = $submission;
}
}
extract($DISPLAY);

--- end code ---
<snip>
Any help is appreciated,

Tom


Your code here looks like it will do what you are intending. The only two
ways to overwrite variables in the session value are to explicitly say
$_SESSION[$something] = $somethingelse, or to use foreach() like this (in
PHP 5):

foreach($arr as &$value) {
//do something to value
}

You said that you have scoured your code for sets on the review page; I
would also check FORM.PHP to see where you are setting anything. I assume
that, like most people, you aren't using the php 5 syntax I mentioned, so
search for all places where you set $_SESSION variables directly. You may
have to post some more code for us to help you out.

Hope this helps.

-Noah
Jul 17 '05 #3
Tom
Thanks for the reply, Noah.

I had checked my code in FORM.PHP, too, so nothing in there should be
causing the problem.

To make sure, I added var_dum for the _SESSION and DISPLAY arrays at
the beginning and end of my REVIEW.PHP page. At the beginning of the
page, DISPLAY is null and the variables in _SESSION for the fields that
weren't filled in on FORM.PHP are empty (or "") -- as expected.

The only operation I run on the _SESSION array after that is that
FOREACH statement described above.

At the end of the page, all the empty _SESSION variables are
repopulated with the BLANK string -- not as expected.
This is all being done in PHP 4.3.4.

Tom

Jul 17 '05 #4
Tom
Update: I've isolated the problem.

I put var_dumps for both arrays right before and after the extract()
function.

It's the extract function that's doing it. When the server runs
extract($DISPLAY) -- it would appear -- it takes the values from the
DISPLAY array and puts them in $_SESSION.

Peculiar -- this couldn't be how it's supposed to work, is it?

Just looked up extract() in the manual:

http://us2.php.net/extract

Maybe if I used one of the extract_type or prefix parameters, it would
stop this?

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Håvard Olerud Eriksen | last post by:
I've been working on a webshop, and I've got most of the functionality up and running. One problem, however, that I don't seem to be able to solve is as follows. My shopping cart is stored in...
5
by: Rob Tweed | last post by:
Probably a simple question but I can't find the answer anyway. Specifically, is it possible to copy a multidimensional array into the $_SESSION array - ie a deep clone of all keys and data? I...
0
by: Phil Powell | last post by:
What is the most standardized method of utilizing the CURL functions in PHP (version 4.3.2) to be able to retrieve the contents of a remote URL that happens to be dependent upon $_SESSION for its...
5
by: h | last post by:
I am at my wits end; I can not see A SINGLE THING I'm doing wrong. I've read every fricking session related doc. I've searched every fricking group. NO ONE seems to have had the problem I'm having...
2
by: Tom | last post by:
I put together a code that checks for 2 post variables then stores them in a multi-dim $_SESSION array, something like this: If ( isset($_POST && isset($_POST) ) { $_SESSION = $_POST;...
12
by: Michael Windsor | last post by:
I've been trying to integrate some PHP pages of my own with some existing code. The details of this are for the support forums for that code (where I have been asking questions), but I wonder if...
2
by: somecrazyguy | last post by:
Take the following code, one would think that there was absolutely no link between $test and $_SESSION. But if you reload the page, guess what... "After=FAILED". Why? Because for some reason,...
2
by: gm04030276 | last post by:
hey, i'm basically trying to use php sessions and a bit of javascript to make tabbed browsing within a web page using sessions to store the data of the different opened pages. Problem: when i unset...
2
by: sharonDonnelly | last post by:
Hi Really dumb problem that's got me beat. Can someone help. The prolem: I'm trying to count the number of times an item has been clicked. There are many items. I want to create a session...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.