mayman212 Posted October 28, 2011 Share Posted October 28, 2011 switch($_GET['action']){ case 'write_ok': $error=false; $msg=''; if($_POST['dateofbirth']=='' || !preg_match( "/^(19|20)\d\d[-\\./](0[1-9]|1[012])[-\\./](0[1-9]|[12][0-9]|3[01])$/",$_POST['dateofbirth'])){ $error=true; $msg.='Date of birth is required and in the correct format 00/00/0000\n'; } the message at the end appears if the error is true. I wanted to know how to not show an errors message if the error is false. Any help on this? Quote Link to comment https://forums.phpfreaks.com/topic/249976-php-error-message/ Share on other sites More sharing options...
silkfire Posted October 28, 2011 Share Posted October 28, 2011 Your logic is screwed. Quote Link to comment https://forums.phpfreaks.com/topic/249976-php-error-message/#findComment-1282956 Share on other sites More sharing options...
dreamwest Posted October 28, 2011 Share Posted October 28, 2011 Use break; to prevent looping example: $x = 2; switch ($x){ case 1: echo "The number is one"; break; case 2: echo "The number is two"; break; case 3: echo "The number is three"; break; default: echo "Number is greater than 3"; } Quote Link to comment https://forums.phpfreaks.com/topic/249976-php-error-message/#findComment-1282959 Share on other sites More sharing options...
AyKay47 Posted October 28, 2011 Share Posted October 28, 2011 Your logic is screwed. not a very helpful post.. OP, if this is the only case that you have.. a switch is not the best way to go about this.. simple if else statements will work.. and it looks to me from the code provided, the the $error variable doesn't really do anything.. if both of your conditions specified are met, then an error message will show.. if the aren't met, the error message will not show.. isn't this what you want? Quote Link to comment https://forums.phpfreaks.com/topic/249976-php-error-message/#findComment-1282962 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.