Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

remember form data after die() ?



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

5+ Year Member


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)

5+ Year Member

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)

5+ Year Member

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)

10+ Year Member

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)

5+ Year Member

I'm using sessions


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

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

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

Featured Threads

Hot Threads This Week

Hot Threads This Month