RE: [PHP] Validating get and post data

From: Date: Tue, 03 Dec 2002 03:45:54 +0000
Subject: RE: [PHP] Validating get and post data
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-126804@lists.php.net to get a copy of this message
> > I think what's happening here is a type issue. The comparison is > returning > a > > boolean, so when $c != '0', the switch is true and the case is resolving > to > > true, and executing. But when $c == '0', with switch is (false), but > the > > case is true. Change the case to > > ($c > chr(58) and $c < chr(58)): > > pass in '09090' and see what you get. Perhaps the case isn't the right > > structure for this test. > > I think you're in the right track. > > Running these would produce different results: > > ---------- script 1 ---------- > $s = '0'; > switch ($s){ > case ($s > chr(47) && $s < chr(58)): > echo 'Yehey!'; > break; > default: > echo 'Boo!'; > } > > ---------- script 2 ---------- > $s = 0; > switch ($s){ > case ($s > chr(47) && $s < chr(58)): > echo 'Yehey!'; > break; > default: > echo 'Boo!'; > } I think the problem is just the incorrect use of a switch. If you change your code to switch(1) then it works as it should. You should be using if..elseif for your style of "cases". ---John Holmes...

« previous php.general (#126804) next »