PHP die() - messes up footer on page

I have a script that does a check on an input form.
If the field is empty, I have it set to die($errormsg) in order to stop the script.
The message tells them that there was an error and give a link back.

But this also stops the include of the footer on the page.
How can I stop the script from doing everything.. but still show the footer.

Ideas?
innercproductionsAsked:
Who is Participating?
 
steelseth12Commented:
you can define your own custom function to handle error messages

$result = mysql_query($query) or custom_die(mysql_error());


function custom_die($error) {

      print $error;
      
      require("footer.php");
      
      exit();
}
0
 
bahadirkocaogluCommented:
You can use DEFINE / DEFINED constants instead die() function.

Please do not use die, you can check your order form via define/defined.

For more:
www.php.net/define
www.php.net/defined
0
 
administradoresCommented:
you can put the footer in a separate file and then something like this:.

<?php

if ($invalidform)
{
require('footer.php');
die($errormsg);
}

//the code if the form is ok

require('footer.php');
?>

0
 
administradoresCommented:
or you can create a function with the footer inside and call it. There are many ways to solve this.
0
 
innercproductionsAuthor Commented:
Wouldn't this put the error message AFTER the footer administradores?

And to bahadirkocaoglu...
Using DEFINE... how would I replace this?

"$result = mysql_query($query) or die ($database_errorinquery);"


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.