silentkillzr Posted November 25, 2009 Share Posted November 25, 2009 if(!isset($msg) and !isset($msg1) and !isset($msg2) and !isset($msg3) and !isset($msg4) and !isset($msg5) and !isset($msg6) and !isset($msg7) and !isset($msg8) and !isset($msg9) and !isset($msg10)) { $regsuccess = "yes" } And i cant seem to get it working, all i get is "Parse error: parse error in blah blah.php on line 101 which this is on." Quote Link to comment https://forums.phpfreaks.com/topic/182871-checking-if-all-msgs-are-empty/ Share on other sites More sharing options...
nethnet Posted November 25, 2009 Share Posted November 25, 2009 "and" is not proper syntax for an If statement. Use "&&" instead. Quote Link to comment https://forums.phpfreaks.com/topic/182871-checking-if-all-msgs-are-empty/#findComment-965246 Share on other sites More sharing options...
Goldeneye Posted November 25, 2009 Share Posted November 25, 2009 Why not put all errors in an array? exampe: $msg = array(); if(<INVALIDUSERNAME>) $msg[] = 'Invalid username'; if(<INVALIDPASSWORD>) $msg[] = 'Invalid Password'; if(<INVALID_EMAIL>) $msg[] = 'Invalid Email'; if(count($msg) == 0) echo 'Yes'; else foreach($msg as $error) echo $error.'<br />'; Quote Link to comment https://forums.phpfreaks.com/topic/182871-checking-if-all-msgs-are-empty/#findComment-965248 Share on other sites More sharing options...
Cosizzle Posted November 25, 2009 Share Posted November 25, 2009 Well, for starters it may help if this were in an array, and in doing so you could check if each message within the array was set. But thats another story. For now this should be what you're after. if ( !isset($msg) && !isset($msg2) && !isset($msg3) && !isset($msg4) && !isset($msg5) && !isset($msg6) && !isset($msg7) && !isset($msg8) && !isset($msg9) && !isset($msg10) ) { $regsuccess = "yes" } Quote Link to comment https://forums.phpfreaks.com/topic/182871-checking-if-all-msgs-are-empty/#findComment-965251 Share on other sites More sharing options...
keldorn Posted November 25, 2009 Share Posted November 25, 2009 I assume your tyring to show error message and also set a flag "$success" which tells the script whether or not to process a certain part. This would be a proper way to show error messages and success message. To answer your question, Put $msg into a array, Like You could have $error['invalid_email'] $error['invalid_name'] , $error['invalid_phone_number'] etc.. Then use empty() to check it.. See the example below. <?php //set variables $success = "" $error = array(); if( <invalid email check here>){ $error['invalid_email'] = "Fix this"; } if(empty($error)){ $success = " Thanks "; // Process further... } ?> <!-- html page --> <?php if(!empty($success)) echo $success; ?> <form action="" method="post"> <dl> <dt><label for="Email">Email</label></dt> <dd><input type="text" value="" id="email" name="email"/><?php if(!empty($error)) echo "<span>{$error['invalid_email']}</span>" ?></dd> </dl> </form> btw I did not test that code, but its the general idea. You can also pass many parameters to isset() so you could do this, (which is really bad and lazy, you should use an array for $msg) if( ! isset($msg1,$msg2,$msg3,$msg4,$msg5,$msg6,$msg7,$msg9)){ } Quote Link to comment https://forums.phpfreaks.com/topic/182871-checking-if-all-msgs-are-empty/#findComment-965254 Share on other sites More sharing options...
Alex Posted November 25, 2009 Share Posted November 25, 2009 "and" is not proper syntax for an If statement. Use "&&" instead. Using "and" is perfectly correct syntax. Quote Link to comment https://forums.phpfreaks.com/topic/182871-checking-if-all-msgs-are-empty/#findComment-965256 Share on other sites More sharing options...
sasa Posted November 25, 2009 Share Posted November 25, 2009 or <?php $test = !isset($msg); for ($i=1; $i<=10;$i++) if (isset(${'msg'.$i})) $test = false; if ($test) $regsuccess = "yes"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/182871-checking-if-all-msgs-are-empty/#findComment-965300 Share on other sites More sharing options...
silentkillzr Posted November 26, 2009 Author Share Posted November 26, 2009 Thanks guys, i went with the array, seems the best option todo. Quote Link to comment https://forums.phpfreaks.com/topic/182871-checking-if-all-msgs-are-empty/#findComment-965753 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.