PHP die() - messes up footer on page

Posted on 2007-07-23
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.

Question by:innercproductions
    LVL 2

    Expert Comment

    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:
    LVL 5

    Expert Comment

    you can put the footer in a separate file and then something like this:.


    if ($invalidform)

    //the code if the form is ok


    LVL 5

    Expert Comment

    or you can create a function with the footer inside and call it. There are many ways to solve this.

    Author Comment

    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);"

    LVL 20

    Accepted Solution

    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;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now