TheFilmGod Posted September 2, 2007 Share Posted September 2, 2007 I have a registration processing form. It goes through all the checking and if an eror occurs it make $error1 or $error2 or... $error7 = true; How can I create an if statement like so: if ( any of $error1, $eror2, $error3, $error4, $error5, $error6, $error7 are true) { do this; } ? ??? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 2, 2007 Share Posted September 2, 2007 try defining all your errors seperate then to call them do an array like $error; and so on Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted September 2, 2007 Share Posted September 2, 2007 Well, given what you've done so far, you're only real option is: <?php if(isset($error1) || isset($error2)|| ...){ //errors } ?> However, your code would be neater and more maintainable if you were to stick your errors into an an array. You could then check the number of elements in the array to see if there are any errors. Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted September 2, 2007 Author Share Posted September 2, 2007 How would I make them in an array? - I never did arrays before. How about this: $error = array(1 => 'empty_user'); ... Later on $error - array(5 => 'different_pass'); How would I see how many elements are in the array? Quote Link to comment Share on other sites More sharing options...
Fadion Posted September 2, 2007 Share Posted September 2, 2007 for($i=1; $i<=7; $i++){ if(!isset(${error . $i})){ echo "Pls fill variable $i"; } } Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted September 2, 2007 Author Share Posted September 2, 2007 I simply did array_key_exists($error) to see if the array even exists if it does than there was an error and I went from there...! Quote Link to comment Share on other sites More sharing options...
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.