sniko Posted November 7, 2010 Posted November 7, 2010 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 Quote
Jordan Palmer Posted November 7, 2010 Posted November 7, 2010 Nice and simple way of doing it there sniko :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.