Jump to content
MakeWebGames

Error Checking, Storing and Showing


sniko

Recommended Posts

Overview

In this tutorial you will learn how to easily display and store errors throughout your code (this will become clear later on), this is a vert fast process and very good when using if's and else's.

 

We store the errors in an array and then display the ones which are needed.

Level: Fairly Easy

 

1) Create the array

$errors = array();

 

2) Add error to array

$errors[] = "bla";

 

3) Display the error

	if(isset($errors) AND count($errors) > 0)
	{
		echo "<h3 class='error'>". count($errors) ." errors occured!</h3>";
		foreach($errors as $msg)
			{									
				echo $start.')'. $msg .'
';
			}
	}

 

Usage

You could use it anywhere necessary, for example on a register page. (see below)

 

	$errors = array();

	//loginname
	if(strlen($loginname) < 5)
		{
			$errors[] = "Please make sure your login name is more than 5 characters in length!";
		}
	if(strlen($loginname) > 15)
		{
			$errors[] = "Please make sure your login name is less than 15 characters in length!";
		}

 

If you have any questions about this method, please reply in this topic.

Many thanks for reading

-sniko

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...