To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
On 04 November 2004 10:20, Stuart Felenstein wrote: > --- Richard Davey <[EMAIL PROTECTED]> wrote: > > > Before setting the session value in Page 2, check > > for the existence of > > the $_POST value first. > > > > if (isset($_POST['var'])) > > { > > $_SESSION['var'] = $_POST['var']; > > } > > > > When you now redirect to Page 2 upon an error, it'll skip this block > > because the $_POST var won't exist. > > > > I'm a bit confused, this fixes the problem ? Of course it does!!!! Well, it's *a* possible fix -- depends on whether it meets your exact requirements. Just follow the data flow to see what's going on: Page 1: the value inserted by the user into form field ListingName is sent, when the Submit button is clicked, to... Page 2: here you copy the value set by the user, and presented to you script in $_POST['ListingName'], into $_SESSION['f1a'] Page 3: if your validity test fails (count($myarray)>5), then you redirect back to... Page 2: here, once again, you attempt to copy $_POST['ListingValue'] into $_SESSION['f1a'] -- but, because, this time, you haven't got here from the form, $_POST will be *empty*, and so $_POST['ListingName'] will equate to NULL (and this access will probably generate a NOTICE, which you would see if you had full error_reporting turned on), so NULL gets assigned into $_SESSION['f1a'], and hey presto! it's gone. (Incidentally, this access to an undefined index of $_POST will probably generate a NOTICE, which you would see if you had full error_reporting turned on.) By testing $_POST['ListingName'] to see if it's isset(), you won't attempt to assign the bogus NULL into $_SESSION['f1a'], and your problem goes away. The only fly in the ointment with this is if your form can be submitted in such a way that $_POST['ListingName'] can legitimately be !isset(). My personal preference here is to set a flag in the session to say your redirecting backwards on error, and then test it before attempting to grab $_POST values (and clear it!). I'd also be very defensive about coding the redirect, and always include a session_write_close() and the SID -- probably in the majority of cases they're not necessary, but at least the code won't fall over if it's ever used somewhere where they are needed. So I'd have something like: Page 2: if (isset($_SESSION['_error_flag']): unset $_SESSION['_error_flag']; // if subsequent logic needs it, I might set a local error flag here // other error actions else: // ok, should be processing a form submission $_SESSION['f1a'] = $_POST['ListingName']; // etc... endif; Page 3: if (count($myarray) > 5): $_SESSION['arrayerr'] = "you have selected too many industries"; session_write_close(); header ("Location: Page2.php?".SID); exit; endif; Hope this helps. Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php