Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6225903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:55:49+00:00 2026-05-24T08:55:49+00:00

I do admit this question is going to be a bit vague, but I

  • 0

I do admit this question is going to be a bit vague, but I will try to explain what I’m trying to accomplish by a few examples. I have some PHP code that loads a bunch of variables from the MySQL database, contains some declarations, some functions to quickly output HTML code etc. However I would love to do all that stuff before anything is sent to the client.

So I do:

<?php
include("somefile.inc");
function bla()
{
    ...
}

if (fails)
    echo "Error: ...<br />";

?>
<!DOCTYPE>
<html>
    <head>
        <script>
            ...
            <?php echo $someString; ?>
            ...
        </script>
    </head>
    <body>
        ...
    </body>
</html>

This is all fine and ok, until I get an error. The echo will not show in the browser because it’s before all HTML… So I modified:

<!DOCTYPE>
<html>
    <head>
        <script>
            ...
            <?php echo $someString; ?>
            ...
        </script>
    </head>
    <body>
        <div class="error_block">
            <?php
            include("somefile.inc");
            function bla()
            {
                ...
            }

            if (fails)
                echo "Error: ...<br />";

            ?>
        </div>

        ...

    </body>
</html>

Now I can actually see errors, which is good. But now the problem arises that in the header, or scrips, I cannot access variables that will be loaded later on in the newly created error_block.

I really don’t like splitting the code in the error_clock to some above the HTML document and some in the error_block. And I also don’t want to use PHP’s die() function which abrubtly ends the execution.

Anyone can give their 2 cents on this issue? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:55:50+00:00Added an answer on May 24, 2026 at 8:55 am

    If you’re looking for an alternate solution, I have one for you. What I like doing is having the logic in before the DOCTYPE

    if(error) { $error = "Please do something" }
    

    Than, down in the document I have a div just for the error (Thanks @Dave for the input)

    <?php echo $error != '' ? '<div id="error">' . $error . '</div>' : ''; ?>
    

    This div will not appear if there isn’t an error (meaning $error is empty) and it makes it easier for you to style the error message the way you would like

    #error { color:red; }
    

    If you want to get fancy, you can use some jQuery to hide/show the div so that the error doesn’t have to persist.

    $('#error').show().delay(7000).fadeOut();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going to give this another try because my last question might have been
I will admit I did minimal research for this question (just a few shallow
This might seem like a stupid question I admit. But I'm in a small
I asked this question earlier today. After trying out suggestions from a few members,
I am going to try to make this question as clear as I can.
I admit this is not strictly a programming question, although I do use my
Background I admit, this question stems from an ultimate lack of deep understanding of
This may seem really silly to you, I admit, but when discussing the Model-View-ViewModel
OK so I admit right off the top that this is a bit screwy
I've seen this and I have to admit I'm pretty impressed: (source: blogspot.com )

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.