> -----Original Message----- > From: Eugene Lee [mailto:[EMAIL PROTECTED] > Sent: Thursday, November 13, 2003 4:28 AM > To: [EMAIL PROTECTED] > Subject: Re: [PHP] $_POST bug? > > > On Thu, Nov 13, 2003 at 04:04:16AM -0500, Jake McHenry wrote: > : > : print_r($_POST) shows me that $_POST has the single 0 > value. I solved > : my problem, instead of having just if ($_POST['test']), I changed it > : to if ($_POST['test'] != ""). Right after I posted, I tried > this, and > : a couple other things.. The problem only happens when I > don't have any > : conditions within the (). > > That's due to PHP's automatic type conversion. In other > words, certain string values can get evaluated to either a > boolean TRUE or FALSE. So you have to do explicit tests. > > For example, what does this code snippet do? > > if ($_POST['test']) > { > do_right(); > } > else > { > do_wrong(); > } > > If $_POST['test'] has an empty string, it calls do_wrong(). > If $_POST['test'] has the string "0", it still calls do_wrong(). > > http://www.php.net/manual/en/language.types.boolean.php#language.types .boolean.casting > >Your move to change your if-statement is a good start to doing the right thing. The next step is to scrub your >$_POST data and make sure that it is valid. > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php
I know this, I said somewhere in one of my posts.. Inside this if statement, I have: If (preg_match_all("/([0-9])/", $_POST['test'], $match) { Do more testing } I just habitually create nested if's.. The problem I was seeing was it was never entering my first if statement, so that's what I posted to the list. I wanted to save a little typing so I just used if ($_POST['test'} for my main conditional. Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php