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

  • Home
  • SEARCH
  • 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 506289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:41:09+00:00 2026-05-13T06:41:09+00:00

I have a php file that contains a HTML form, then PHP logic, then

  • 0

I have a php file that contains a HTML form, then PHP logic, then an HTML footer…in that order.

I am trying to get the values from the form into some php validation logic in the botton of the page (but before the footer) using <?php VALIDATION LOGIC HERE ?>.

the problem is when the validation finds an error, the php logic will die() and hence, my HTML footer will not be executed.

is there a way to get my HTML footer to execute despite my php die();? …or is there a better overall way to integrate my HTML and PHP? Thanks! Anyhelp would be much appreciated.


EDIT:
I actually have die() almost everywhere in my code where I am about to connect to a database. If the user credentials are correct, they connect..if credentials are wrong then it will die()..

Is this good practice and use of die()? it seems the solution to my problem is to use return() INSTEAD OF die()…in order to continue processing the HTML footer.

Also, I have situations such as mysql_connect() or die(). How can i would continue processing the remaining HTML page when die() is executed before the HTML is processed? ..i don’t think mysql_connect() or return; is good practice right?

Thanks so much again in advance! The feedback has been very helpful!

  • 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-13T06:41:09+00:00Added an answer on May 13, 2026 at 6:41 am

    As other states, you should have multiple files; header.php, index.php, footer.php, formvalidator.php.
    In your index.php file, you should include header.php and footer.php.
    In the form tag, action is sett to load formvalidator.php

    In the form validator script, you could have something like this:

      // All form fields are identified by '[id]_[name]', where 'id' is the 
      // identifier of the form type.
      // The field identifier we want to return is just the name and not the id.
      public function getFormData() {
        $formData = array();
        foreach ($_POST as $key => $value) 
        {
          // Remove [id]_ 
          $name = preg_replace('!.*_!', '', $key);
    
          if (is_array($value)) {
            $formData[$name] = implode(',', $value);
          } else {
            $formData[$name] = $value;
          }
        }
        return $formData;
      } 
    

    Now you can loop through the array and validate each field.
    If you find an error, echo an error message, otherwise process the form.

    Update
    Answer to your update.

    You should “never” use die(). Instead, exit thefunction you are in and return an error message. If you simply die(), you never know what went wrong where.

    It is not possible to do server validation of a form unless you click the submit button.
    You can put the code I gave you in the same PHP file as the form, and when you submit, you simply reload the same page (just set action="<?= $_SERVER['PHP_SELF'] ?>")

    If you want to validate fields before submit, you must to this using javascript, like e.g. jQuery.validate.

    Hmm… seem like you need some more knowledge of how to mix PHP with HTML.
    Take a look at this beginners guide on how to work with forms in PHP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 385k
  • Answers 385k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Google has to discover your site -- it can't just… May 14, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer Throw this code away. Seperate your html files from your… May 14, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer <FilesMatch "\.(htaccess|htpasswd|ini|log|sh|inc|bak)$"> Order Allow,Deny Deny from all </FilesMatch> Loaded with… May 14, 2026 at 11:31 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.