homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

remember form data after die() ?

 4:10 pm on Mar 23, 2008 (gmt 0)


I've noticed this issue in my form. When the script checks for empty fields, if it finds any, it exits using die("empty fields found");. But the problem is that afterwards all the values that where inputed by the user are removed and I get a blank form with the error underneath it.

Is there any way for the form to stay filled after the die()?

Thank you

// form.php:

<html form>
if(isset($_GET['submit'])) {


if (empty($value1) empty($value2) empty($value3)) {
die ("Empty fields found"};
} else {
rest of php



 4:37 pm on Mar 23, 2008 (gmt 0)

Do you mean when you press back on your browser? does it not remember variables when you refresh the page?

What it should do is re-submit the form when you press refresh. Is this not what happens?


 5:01 pm on Mar 23, 2008 (gmt 0)

It shows the die() bellow the form, and after the die() all the values are deleted. I could post a link for more clarification, but as I understand that's against the rules?

echo '<form>..';
if(isset($_GET['submit'])) {
if (empty..) {
die("Empty fields found");


 9:27 am on Mar 24, 2008 (gmt 0)

Once you use die() your script will lose all it's data unless you use a method of persistence such as serialize()/unserialize(), sessions, or a persistent cache like APC.



 11:33 am on Mar 24, 2008 (gmt 0)

I'm using sessions


 1:18 pm on Mar 24, 2008 (gmt 0)

IF you use sessions
then in order to assure that the scripts will not be "confused"
you will just need to start by adding on the first script an "IF" to check if incoming inputs from the landing page are from POST or SESSION
then on the landing page
if isset and !empty $_POST['my_stuff'];
create your my_stuff session

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved