Re: [PHP] $_POST bug?
On Thu, Nov 13, 2003 at 12:59:11AM -0500, Jake McHenry wrote: : : -Original Message- : From: Jake McHenry [mailto:[EMAIL PROTECTED] : Sent: Thursday, November 13, 2003 12:53 AM : To: [EMAIL PROTECTED] : Subject: [PHP] $_POST bug? : : I have 5 fields, all 1 character in length, numbers being : entered. If zero's are entered in the boxes, and the form is : submitted, the corresponding $_POST variables are empty? Is : there a way around this, or am I doing something wrong? : : I guess I could just do, if (isset(... Blah.. Then if it's : not set then manually set the variable name to 0... : : Just to test, I changed the input field length to 3, and every time I : tried it, single 0 does not create the $_POST variable. Double 0's : create it, along with any other numbers, it's only when a single 0 is : entered. Is this a bug or happening for a reason? In your form handler script, what does print_r($_POST) come out with? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] $_POST bug?
My system (win2000 IIS) also handles 0, and webserver (redhat apache) also handles 0. Your system sounds faulty in some way, what browser are U using and what version of PHP. I know from earlier experience that some versions of Netscape behaves strange on the form elements, meaning when posting / getting the data back to the server. I remember this as one of my domain search utilities always came emtpy in netscape, and not in Opera and Explorer. So it could be this, but if youre not on Netscape - Its not this. :) Kim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] $_POST bug?
-Original Message- From: Eugene Lee [mailto:[EMAIL PROTECTED] Sent: Thursday, November 13, 2003 3:48 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] $_POST bug? On Thu, Nov 13, 2003 at 12:59:11AM -0500, Jake McHenry wrote: : : -Original Message- : From: Jake McHenry [mailto:[EMAIL PROTECTED] : Sent: Thursday, November 13, 2003 12:53 AM : To: [EMAIL PROTECTED] : Subject: [PHP] $_POST bug? : : I have 5 fields, all 1 character in length, numbers being : entered. If zero's are entered in the boxes, and the form is : submitted, the corresponding $_POST variables are empty? Is : there a way around this, or am I doing something wrong? : : I guess I could just do, if (isset(... Blah.. Then if it's : not set then manually set the variable name to 0... : : Just to test, I changed the input field length to 3, and every time I : tried it, single 0 does not create the $_POST variable. Double 0's : create it, along with any other numbers, it's only when a single 0 is : entered. Is this a bug or happening for a reason? In your form handler script, what does print_r($_POST) come out with? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php 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 (). 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
RE: [PHP] $_POST bug?
-Original Message- From: Kim Steinhaug [mailto:[EMAIL PROTECTED] Sent: Thursday, November 13, 2003 3:28 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] $_POST bug? My system (win2000 IIS) also handles 0, and webserver (redhat apache) also handles 0. Your system sounds faulty in some way, what browser are U using and what version of PHP. I know from earlier experience that some versions of Netscape behaves strange on the form elements, meaning when posting / getting the data back to the server. I remember this as one of my domain search utilities always came emtpy in netscape, and not in Opera and Explorer. So it could be this, but if youre not on Netscape - Its not this. :) Kim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I've tried it on opera, netscape, IE, and mozilla right on the server. It seems to be a php condition thing, not really what's in the $_POST array, as I just posted print_r($_POST) does contain the values, it's only when I have if ($_POST['test']) that the problem occurs. 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
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
Re: [PHP] $_POST bug?
Hi, (I think you intended to send this to the list...) On Thu, 13 Nov 2003 02:03:50 -0500 Jake McHenry [EMAIL PROTECTED] wrote: ...[snip]... I'm running RHLinux 9, php 4.2.2, apache 2.0.40 Hmm... same here. Only difference could be that I rebuilt the php RPMs to support mbstring--I'm sure it's not related though ;) if (($_POST['accid_1']) ($_POST['accid_2']) ($_POST['accid_3']) ($_POST['accid_4']) ($_POST['accid_5'])){ do my stuff... } All variables are 1 character long, and should be numbers. I have a preg_match inside the condition.. But it wasn't even getting that far. (Just a note: If they should be numbers, maybe you can use is_numeric().) But when any of the values were 0, then it didn't do my stuff, which kinda caught my attention... lol In the above, you're basically asking if (all of these are TRUE) { do my stuff... } So, if even one of those is 0 then it won't do your stuff... *** I just seemed to fix the problem, I changed the above code to($_POST['accid'] != ) for each one, and it works now... ? Could someone please enlighten me as to what's happening here? Well, this if ($_POST['accid']) is asking something like if (TRUE) so if the value of $_POST is 0 then it's FALSE. If the value is 1 or a or Edwin then that would evaluate to TRUE. Whereas this one if ($_POST['accid'] != ) is asking something like if the value of $_POST is not equal to then... So, since 0 is not equal to then the result would be TRUE. If the value 1 or a or Edwin then that would STILL evaluate to TRUE since those are not equal to . Not sure if I had explained this well since I'm starting to have a headache trying to figure out how to explain 'What is TRUE?' Not 'FALSE'. Then, what is 'FALSE'? Not 'TRUE'. ??. :) - E - __ Do You Yahoo!? Yahoo! BB is Broadband by Yahoo! http://bb.yahoo.co.jp/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] $_POST bug?
Jake McHenry wrote: I've tried it on opera, netscape, IE, and mozilla right on the server. It seems to be a php condition thing, not really what's in the $_POST array, as I just posted print_r($_POST) does contain the values, it's only when I have if ($_POST['test']) that the problem occurs. Any non-zero number evaluates to true. In your statement, you are essentially asking if the value of $_POST['test'] is greater than 0 which would return true. So if test = 0, then the if condition fails, hence why you are getting your problems. -- Burhan Khalid phplist[at]meidomus[dot]com http://www.meidomus.com --- Documentation is like sex: when it is good, it is very, very good; and when it is bad, it is better than nothing. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] $_POST bug?
--- Jake McHenry [EMAIL PROTECTED] 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 (). Your problem has nothing to do with POST then. if (0) { echo 'This will never print'; } Hope that helps. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] $_POST bug?
-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
RE: [PHP] $_POST bug?
-Original Message- From: Jake McHenry [mailto:[EMAIL PROTECTED] Sent: Thursday, November 13, 2003 12:53 AM To: [EMAIL PROTECTED] Subject: [PHP] $_POST bug? I have 5 fields, all 1 character in length, numbers being entered. If zero's are entered in the boxes, and the form is submitted, the corresponding $_POST variables are empty? Is there a way around this, or am I doing something wrong? I guess I could just do, if (isset(... Blah.. Then if it's not set then manually set the variable name to 0... Has anyone else run across this? 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 Just to test, I changed the input field length to 3, and every time I tried it, single 0 does not create the $_POST variable. Double 0's create it, along with any other numbers, it's only when a single 0 is entered. Is this a bug or happening for a reason? 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
Re: [PHP] $_POST bug?
On Thu, 13 Nov 2003 00:59:11 -0500 Jake McHenry [EMAIL PROTECTED] wrote: ...[snip]... Just to test, I changed the input field length to 3, and every time I tried it, single 0 does not create the $_POST variable. Double 0's create it, along with any other numbers, it's only when a single 0 is entered. Is this a bug or happening for a reason? Ans.: happening for a reason :) Works here even with single 0. Post some relevant code and if possible your environment as well. - E - __ Do You Yahoo!? Yahoo! BB is Broadband by Yahoo! http://bb.yahoo.co.jp/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] $_POST bug?
On Thursday 13 November 2003 00:59, Jake McHenry wrote: -Original Message- From: Jake McHenry [mailto:[EMAIL PROTECTED] Sent: Thursday, November 13, 2003 12:53 AM To: [EMAIL PROTECTED] Subject: [PHP] $_POST bug? I have 5 fields, all 1 character in length, numbers being entered. If zero's are entered in the boxes, and the form is submitted, the corresponding $_POST variables are empty? Is there a way around this, or am I doing something wrong? I guess I could just do, if (isset(... Blah.. Then if it's not set then manually set the variable name to 0... Has anyone else run across this? 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 Just to test, I changed the input field length to 3, and every time I tried it, single 0 does not create the $_POST variable. Double 0's create it, along with any other numbers, it's only when a single 0 is entered. Is this a bug or happening for a reason? Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com PHP uses the 0 as the flag for FALSE. And anything other then 0 is TRUE. If I understand the workings of PHP FALSE can also be interpreted as NULL. So PHP sees the post as saying the fields are NULL. I could be wrong on this but I think that's where the problem is. Whether the developers planned this or it's slipped through that cracks I have no idea. Did you checkout http://bugs.php.net to see if there's anything listed about it? -- I have a photographic memory. I just forgot the film --Unknown = Ryan Thompson [EMAIL PROTECTED] http://osgw.sourceforge.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php