Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP die() - messes up footer on page

Posted on 2007-07-23
5
Medium Priority
?
360 Views
Last Modified: 2009-07-29
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?
0
Comment
Question by:innercproductions
5 Comments
 
LVL 2

Expert Comment

by:bahadirkocaoglu
ID: 19549265
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
 
LVL 5

Expert Comment

by:administradores
ID: 19549351
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
 
LVL 5

Expert Comment

by:administradores
ID: 19549375
or you can create a function with the footer inside and call it. There are many ways to solve this.
0
 

Author Comment

by:innercproductions
ID: 19549660
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
 
LVL 20

Accepted Solution

by:
steelseth12 earned 2000 total points
ID: 19550052
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month20 days, 17 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question