Jump to content
Larry Ullman's Book Forums

The Order That The Code Is In.


Recommended Posts

Hi all. I had a general question about writing the php code for this book. Let's take script 12.1 as an example. The order of the code is to handle errors first, then display the form. Why isn't it the other way around so that the code is written as displaying the form and then handling the errors? When the browser displays the page for the first time there won't be any errors to handle, right? Is the order important?

Link to comment
Share on other sites

Hello and welcome to the forums.

 

You have to handle the errors first because if there are any errors, you need to be able to change the displaying of the form accordingly to let the user know that there are some problems.

In the event that the form is being loading for the first time, because the $_POST variable will not be set, the if statement that checks whether the $_POST variable is set or not will evaluate to false, and all the logic that checks for any errors will be skipped over.

 

Does that make sense?

  • Upvote 2
Link to comment
Share on other sites

 Share

×
×
  • Create New...