RE: [PHP] empty and isset
-Original Message- From: Sunfire [mailto:[EMAIL PROTECTED]] Sent: 06 February 2003 21:27 actually so does empty end up testing true on an empty var... thats because empty thinks or string(0) is actually a string just blank... a trick to do with empty is use !empty which will say if the string is at least 1 char long other wish if it is less than 1 char long even though a string does exist then it must be empty.. because: if(empty(var)){ echo its blank;//eek doesnt work cuz string does exist }else{ echo something in there;//defaults regardless string(0) //is a string so above block will never be used //im sort of confused because: if(!empty(var)){ echo something in there;//it works for a wierd reason }else{ echo its blank//works if string(0) or null exists } its strange that !empty will always return a 0 char string/null as false but empty it doesnt care its always true regardless... any reason for that? cuz im confused as to why you have to use !empty instead of empty OK, let's set some of this confusion to rest: isset($x) will be TRUE if $x *both*: - exists as a variable in the current scope (even if it has not yet been assigned a value, as might happen if you use a var or global declaration). - is not NULL empty($x) will be TRUE if $x is *any* of the following: - a non-existent variable (in the current scope) - NULL - a numeric 0 (or 0.0) - the empty string () or the string 0 - an empty array is_null($x) is the same as !isset($x), except that is_null() produces an undefined variable notice if $x does not exist (which you will not see if your error_reporting is set not to display notices, or if you suppress it with @). and finally, if($x) is the same as if(!empty($x)), except that if($x) will also produce an undefined variable notice. This is all defined in the online manual, although it's sometimes a bit hard to digest. There's also a great little set of tables that may help you visualize things better at http://www.blueshoes.org/en/developer/php_cheat_sheet/ Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] empty and isset
Actually, I believe it's not a matter of the input being set, but the fact that isset() returns true on an empty variable. Jason Wong php-general@gremTo: [EMAIL PROTECTED] lins.bizcc: Subject: Re: [PHP] empty and isset 02/06/2003 12:31 AM Please respond to php-general On Thursday 06 February 2003 13:20, Bryan Lipscy wrote: Env: Slackware 8.1, Apache 1.3.27, PHP 4.3.0 Bugs: None found for these issues. I am running to this same problem. The isset() function appears to have problems with the empty text value. The empty() function sees the value of $_POST['q1'] as expected. So why is both isset() and empty() returning true on q1? input of type text are set regardless of whether you have entered anything. Thus isset() returns true. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Have you noticed that all you need to grow healthy, vigorous grass is a crack in your sidewalk? */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] empty and isset
On Thursday 06 February 2003 22:50, [EMAIL PROTECTED] wrote: input of type text are set regardless of whether you have entered anything. Thus isset() returns true. Actually, I believe it's not a matter of the input being set, but the fact that isset() returns true on an empty variable. Try this: ?php if (isset($doo)) { print '$doo is set'; // does not get printed } if (empty($doo)) { print '$doo is empty'; // gets printed } ? -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* The solution to a problem changes the nature of the problem. -- Peer */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] empty and isset
It's fairly easy. isset returns true if the VARIABLE itself exists, like if it's been declared, or set by a form. isset isn't checking the VALUE of the VARIABLE, just if it exists. In Jason's example below, isset returns false because the VARIABLE was never declared in some way, shape or form. Technically, it doesn't exist. empty returns true because the VARIABLE $doo, declared or not, has no VALUE. VARIABLE and VALUE...two different things. Jason Wong wrote: On Thursday 06 February 2003 22:50, [EMAIL PROTECTED] wrote: input of type text are set regardless of whether you have entered anything. Thus isset() returns true. Actually, I believe it's not a matter of the input being set, but the fact that isset() returns true on an empty variable. Try this: ?php if (isset($doo)) { print '$doo is set'; // does not get printed } if (empty($doo)) { print '$doo is empty'; // gets printed } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] empty and isset
Thanks for clearing that up. So input of type text does a set, which makes isset() true, but isset() does not return true if $var is merely empty. Jason Wong php-general@gremTo: [EMAIL PROTECTED] lins.bizcc: Subject: Re: [PHP] empty and isset 02/06/2003 11:28 AM Please respond to php-general On Thursday 06 February 2003 22:50, [EMAIL PROTECTED] wrote: input of type text are set regardless of whether you have entered anything. Thus isset() returns true. Actually, I believe it's not a matter of the input being set, but the fact that isset() returns true on an empty variable. Try this: ?php if (isset($doo)) { print '$doo is set'; // does not get printed } if (empty($doo)) { print '$doo is empty'; // gets printed } ? -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* The solution to a problem changes the nature of the problem. -- Peer */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] empty and isset
On Friday 07 February 2003 01:35, [EMAIL PROTECTED] wrote: Thanks for clearing that up. Hmm, it seems like you still haven't grasped it yet :) So input of type text does a set, which makes isset() true, Correct. but isset() does not return true if $var is merely empty. Incorrect. Basically empty($var) returns TRUE if $var evaluates to FALSE, and in this context if $var is undefined it evaluates to FALSE. isset($var) returns TRUE if $var has been defined is a non-NULL value, and returns FALSE if $var is undefined or is set to NULL. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Conquering Russia should be done steppe by steppe. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] empty and isset
you need to test for empty strings such as which variables have when you submit an empty form .. if(!empty(varname) !empty(varname2) !empty(varname 3)..){ //do whatever if they have something usefull in them //this block of code will be ran if var_dumb() on all the //vars tested is than string(0) }else{ //do whatever if string().. is anything else } - Original Message - From: Bryan Lipscy [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, February 06, 2003 12:20 AM Subject: RE: [PHP] empty and isset Env: Slackware 8.1, Apache 1.3.27, PHP 4.3.0 Bugs: None found for these issues. I am running to this same problem. The isset() function appears to have problems with the empty text value. The empty() function sees the value of $_POST['q1'] as expected. So why is both isset() and empty() returning true on q1? I included the is_null() to verify that the value is definitely not null. Submitting the empty form yields these results: Value of q1 == Value of q1 is NOT NULL Q1 is empty q2 is empty q3 is empty q4 is empty Values for q2, q3, and q4 all return as expected. Source follows: !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN HTML HEAD TITLE PHP Test /TITLE META NAME=Generator CONTENT=EditPlus META NAME=Author CONTENT= META NAME=Keywords CONTENT= META NAME=Description CONTENT= /HEAD BODY FORM action=test.php method=POST span id=q1Text: INPUT name=q1 type=text maxlength=128 value=/spanbr span id=q2Radio: input name=qa2 type=radio value=1 input name=qa2 type=radio value=2 input name=qa2 type=radio value=3 input name=qa2 type=radio value=4 /spanbr span id=q3Checkbox: input type=checkbox name=qa3 value=9/spanbr input type=submit value=Submit input type=Reset name=Resetbr /FORM /BODY /HTML PHP Source: ? if (isset($_POST['q1'])){ print Value of q1 == .$_POST['q1'].br; } if (is_null($_POST['q1'])){ print Value of q1 is nullbr; } else { print Value of q1 is NOT NULLbr; } if (empty($_POST['q1'])){ print Q1 is emptybr; } if (isset($_POST['q2'])){ print Value of q2 == .$_POST['q2'].br; } if (empty($_POST['q2'])){ print q2 is emptybr; } if (isset($_POST['q3'])){ print Value of q3 == .$_POST['q3'].br; } if (empty($_POST['q3'])){ print q3 is emptybr; } if (isset($_POST['q4'])){ print Value of q4 == .$_POST['q4'].br; } if (empty($_POST['q4'])){ print q4 is emptybr; } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.443 / Virus Database: 248 - Release Date: 1/10/2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] empty and isset
actually so does empty end up testing true on an empty var... thats because empty thinks or string(0) is actually a string just blank... a trick to do with empty is use !empty which will say if the string is at least 1 char long other wish if it is less than 1 char long even though a string does exist then it must be empty.. because: if(empty(var)){ echo its blank;//eek doesnt work cuz string does exist }else{ echo something in there;//defaults regardless string(0) //is a string so above block will never be used //im sort of confused because: if(!empty(var)){ echo something in there;//it works for a wierd reason }else{ echo its blank//works if string(0) or null exists } its strange that !empty will always return a 0 char string/null as false but empty it doesnt care its always true regardless... any reason for that? cuz im confused as to why you have to use !empty instead of empty - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, February 06, 2003 9:50 AM Subject: Re: [PHP] empty and isset Actually, I believe it's not a matter of the input being set, but the fact that isset() returns true on an empty variable. Jason Wong php-general@gremTo: [EMAIL PROTECTED] lins.bizcc: Subject: Re: [PHP] empty and isset 02/06/2003 12:31 AM Please respond to php-general On Thursday 06 February 2003 13:20, Bryan Lipscy wrote: Env: Slackware 8.1, Apache 1.3.27, PHP 4.3.0 Bugs: None found for these issues. I am running to this same problem. The isset() function appears to have problems with the empty text value. The empty() function sees the value of $_POST['q1'] as expected. So why is both isset() and empty() returning true on q1? input of type text are set regardless of whether you have entered anything. Thus isset() returns true. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Have you noticed that all you need to grow healthy, vigorous grass is a crack in your sidewalk? */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.443 / Virus Database: 248 - Release Date: 1/10/2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] empty and isset
They both work, you're just not using the correct logic or something. Show your code again... your actual code that isn't working (so you say) and the form that's being submitted. Also, is register_globals on or off? Load this small bit of code as proof that it works: form method=POST input type=text name=name input type=submit /form ? if(isset($_POST['name'])) { echo You submitted a name ; if(empty($_POST['name'])) { echo that was blank.; } else { echo of {$_POST['name']}; } } ? ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -Original Message- From: Sunfire [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 05, 2003 8:08 PM To: [EMAIL PROTECTED] Subject: [PHP] empty and isset i tried to use empty and isset to check and see if variables were being used in a form.. im not getting any kind of good answer from the server when i try using empty and isset... it all works the same and that is cut out anything regardless of if it was used or not... any thing to help? the docs didnt seem to be much help and im sort of confused --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.443 / Virus Database: 248 - Release Date: 1/10/2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] empty and isset
ok i dont know if this will help at all since the code that doesnt work wont fit in the message (got error saying i cant send that much all at once) this is what i got out of var_dump.. first set of variables: $member[Areacode1]=string(3)123 123 $member[Exchange1]=string(3)123123 $member[Number1]=string(4)12341234 those variables im not worried about because they are required in the form. the next ones i want to exclude from the list all together if string()==0 on all 3 variables.. here is the var dumb from them: $member[AreaCode2]string(0) $member[Exchange2]string(0) $member[Number2]string(0) here is the seudo code for what i need to do: if $member[AreaCode] $member[Exchange2] $member[Number2] is empty, null == or has string(0) in it { //exclude vars from list alltogether } any other conditions{ //print the vars in the list } - Original Message - From: John W. Holmes [EMAIL PROTECTED] To: 'Sunfire' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, February 05, 2003 9:57 PM Subject: RE: [PHP] empty and isset They both work, you're just not using the correct logic or something. Show your code again... your actual code that isn't working (so you say) and the form that's being submitted. Also, is register_globals on or off? Load this small bit of code as proof that it works: form method=POST input type=text name=name input type=submit /form ? if(isset($_POST['name'])) { echo You submitted a name ; if(empty($_POST['name'])) { echo that was blank.; } else { echo of {$_POST['name']}; } } ? ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -Original Message- From: Sunfire [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 05, 2003 8:08 PM To: [EMAIL PROTECTED] Subject: [PHP] empty and isset i tried to use empty and isset to check and see if variables were being used in a form.. im not getting any kind of good answer from the server when i try using empty and isset... it all works the same and that is cut out anything regardless of if it was used or not... any thing to help? the docs didnt seem to be much help and im sort of confused --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.443 / Virus Database: 248 - Release Date: 1/10/2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.443 / Virus Database: 248 - Release Date: 1/11/2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] empty and isset
If(!empty($member['Areacode2']) || !empty($member['Exchange2']) || !empty($member['Number2'])) { echo $member['Areacode2'] . '-' . $member['Exchange2'] . '-' . $member['Number2']; } The mail wrapping will mess that up, but hopefully you get the idea. You're looking for Areacode2 OR Exchange2 OR Number2 being NOT (that's what the ! is for) empty. If any of them are not empty, then you print out their values. If you only want it displayed if all of them are NOT empty, then change the || (which means OR) to (which means AND). A single means a bitwise AND, which you don't want to mess with. Hope that helps. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -Original Message- From: Sunfire [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 06, 2003 12:02 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] empty and isset ok i dont know if this will help at all since the code that doesnt work wont fit in the message (got error saying i cant send that much all at once) this is what i got out of var_dump.. first set of variables: $member[Areacode1]=string(3)123 123 $member[Exchange1]=string(3)123123 $member[Number1]=string(4)12341234 those variables im not worried about because they are required in the form. the next ones i want to exclude from the list all together if string()==0 on all 3 variables.. here is the var dumb from them: $member[AreaCode2]string(0) $member[Exchange2]string(0) $member[Number2]string(0) here is the seudo code for what i need to do: if $member[AreaCode] $member[Exchange2] $member[Number2] is empty, null == or has string(0) in it { //exclude vars from list alltogether } any other conditions{ //print the vars in the list } - Original Message - From: John W. Holmes [EMAIL PROTECTED] To: 'Sunfire' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, February 05, 2003 9:57 PM Subject: RE: [PHP] empty and isset They both work, you're just not using the correct logic or something. Show your code again... your actual code that isn't working (so you say) and the form that's being submitted. Also, is register_globals on or off? Load this small bit of code as proof that it works: form method=POST input type=text name=name input type=submit /form ? if(isset($_POST['name'])) { echo You submitted a name ; if(empty($_POST['name'])) { echo that was blank.; } else { echo of {$_POST['name']}; } } ? ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -Original Message- From: Sunfire [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 05, 2003 8:08 PM To: [EMAIL PROTECTED] Subject: [PHP] empty and isset i tried to use empty and isset to check and see if variables were being used in a form.. im not getting any kind of good answer from the server when i try using empty and isset... it all works the same and that is cut out anything regardless of if it was used or not... any thing to help? the docs didnt seem to be much help and im sort of confused --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.443 / Virus Database: 248 - Release Date: 1/10/2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.443 / Virus Database: 248 - Release Date: 1/11/2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] empty and isset
Env: Slackware 8.1, Apache 1.3.27, PHP 4.3.0 Bugs: None found for these issues. I am running to this same problem. The isset() function appears to have problems with the empty text value. The empty() function sees the value of $_POST['q1'] as expected. So why is both isset() and empty() returning true on q1? I included the is_null() to verify that the value is definitely not null. Submitting the empty form yields these results: Value of q1 == Value of q1 is NOT NULL Q1 is empty q2 is empty q3 is empty q4 is empty Values for q2, q3, and q4 all return as expected. Source follows: !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN HTML HEAD TITLE PHP Test /TITLE META NAME=Generator CONTENT=EditPlus META NAME=Author CONTENT= META NAME=Keywords CONTENT= META NAME=Description CONTENT= /HEAD BODY FORM action=test.php method=POST span id=q1Text: INPUT name=q1 type=text maxlength=128 value=/spanbr span id=q2Radio: input name=qa2 type=radio value=1 input name=qa2 type=radio value=2 input name=qa2 type=radio value=3 input name=qa2 type=radio value=4 /spanbr span id=q3Checkbox: input type=checkbox name=qa3 value=9/spanbr input type=submit value=Submit input type=Reset name=Resetbr /FORM /BODY /HTML PHP Source: ? if (isset($_POST['q1'])){ print Value of q1 == .$_POST['q1'].br; } if (is_null($_POST['q1'])){ print Value of q1 is nullbr; } else { print Value of q1 is NOT NULLbr; } if (empty($_POST['q1'])){ print Q1 is emptybr; } if (isset($_POST['q2'])){ print Value of q2 == .$_POST['q2'].br; } if (empty($_POST['q2'])){ print q2 is emptybr; } if (isset($_POST['q3'])){ print Value of q3 == .$_POST['q3'].br; } if (empty($_POST['q3'])){ print q3 is emptybr; } if (isset($_POST['q4'])){ print Value of q4 == .$_POST['q4'].br; } if (empty($_POST['q4'])){ print q4 is emptybr; } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] empty and isset
yes tnx that did work now any blank variable i need tested in that set wont show up on the list.. i have a few other bugs to work out with printing and formatting but will take care of that a little later... - Original Message - From: John W. Holmes [EMAIL PROTECTED] To: 'Sunfire' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, February 06, 2003 12:08 AM Subject: RE: [PHP] empty and isset If(!empty($member['Areacode2']) || !empty($member['Exchange2']) || !empty($member['Number2'])) { echo $member['Areacode2'] . '-' . $member['Exchange2'] . '-' . $member['Number2']; } The mail wrapping will mess that up, but hopefully you get the idea. You're looking for Areacode2 OR Exchange2 OR Number2 being NOT (that's what the ! is for) empty. If any of them are not empty, then you print out their values. If you only want it displayed if all of them are NOT empty, then change the || (which means OR) to (which means AND). A single means a bitwise AND, which you don't want to mess with. Hope that helps. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -Original Message- From: Sunfire [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 06, 2003 12:02 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] empty and isset ok i dont know if this will help at all since the code that doesnt work wont fit in the message (got error saying i cant send that much all at once) this is what i got out of var_dump.. first set of variables: $member[Areacode1]=string(3)123 123 $member[Exchange1]=string(3)123123 $member[Number1]=string(4)12341234 those variables im not worried about because they are required in the form. the next ones i want to exclude from the list all together if string()==0 on all 3 variables.. here is the var dumb from them: $member[AreaCode2]string(0) $member[Exchange2]string(0) $member[Number2]string(0) here is the seudo code for what i need to do: if $member[AreaCode] $member[Exchange2] $member[Number2] is empty, null == or has string(0) in it { //exclude vars from list alltogether } any other conditions{ //print the vars in the list } - Original Message - From: John W. Holmes [EMAIL PROTECTED] To: 'Sunfire' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, February 05, 2003 9:57 PM Subject: RE: [PHP] empty and isset They both work, you're just not using the correct logic or something. Show your code again... your actual code that isn't working (so you say) and the form that's being submitted. Also, is register_globals on or off? Load this small bit of code as proof that it works: form method=POST input type=text name=name input type=submit /form ? if(isset($_POST['name'])) { echo You submitted a name ; if(empty($_POST['name'])) { echo that was blank.; } else { echo of {$_POST['name']}; } } ? ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -Original Message- From: Sunfire [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 05, 2003 8:08 PM To: [EMAIL PROTECTED] Subject: [PHP] empty and isset i tried to use empty and isset to check and see if variables were being used in a form.. im not getting any kind of good answer from the server when i try using empty and isset... it all works the same and that is cut out anything regardless of if it was used or not... any thing to help? the docs didnt seem to be much help and im sort of confused --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.443 / Virus Database: 248 - Release Date: 1/10/2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.443 / Virus Database: 248 - Release Date: 1/11/2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.443 / Virus Database: 248 - Release Date: 1/10/2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] empty and isset
On Thursday 06 February 2003 13:20, Bryan Lipscy wrote: Env: Slackware 8.1, Apache 1.3.27, PHP 4.3.0 Bugs: None found for these issues. I am running to this same problem. The isset() function appears to have problems with the empty text value. The empty() function sees the value of $_POST['q1'] as expected. So why is both isset() and empty() returning true on q1? input of type text are set regardless of whether you have entered anything. Thus isset() returns true. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Have you noticed that all you need to grow healthy, vigorous grass is a crack in your sidewalk? */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] empty and isset
Env: Slackware 8.1, Apache 1.3.27, PHP 4.3.0 Bugs: None found for these issues. I am running to this same problem. The isset() function appears to have problems with the empty text value. The empty() function sees the value of $_POST['q1'] as expected. So why is both isset() and empty() returning true on q1? Because the variable is set (isset() TRUE) _and_ it's empty (empty() TRUE). It means it's a valid variable that has a value of zero or an empty string (empty string in this case, since it's coming from a form) I included the is_null() to verify that the value is definitely not null. Submitting the empty form yields these results: Value of q1 == Value of q1 is NOT NULL Q1 is empty q2 is empty q3 is empty q4 is empty These are all correct. I'll explain it below. Values for q2, q3, and q4 all return as expected. Source follows: !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN HTML HEAD TITLE PHP Test /TITLE META NAME=Generator CONTENT=EditPlus META NAME=Author CONTENT= META NAME=Keywords CONTENT= META NAME=Description CONTENT= /HEAD BODY FORM action=test.php method=POST span id=q1Text: INPUT name=q1 type=text maxlength=128 value=/spanbr span id=q2Radio: input name=qa2 type=radio value=1 input name=qa2 type=radio value=2 input name=qa2 type=radio value=3 input name=qa2 type=radio value=4 /spanbr span id=q3Checkbox: input type=checkbox name=qa3 value=9/spanbr input type=submit value=Submit input type=Reset name=Resetbr /FORM /BODY /HTML PHP Source: ? if (isset($_POST['q1'])){ print Value of q1 == .$_POST['q1'].br; } This will always be true for a text box. When the form is submitted, $_POST['q1'] will always be set. It's either set to an empty string or it's set to the value you type in the box. if (is_null($_POST['q1'])){ print Value of q1 is nullbr; } else { print Value of q1 is NOT NULLbr; } This will always be FALSE for a textbox. if (empty($_POST['q1'])){ print Q1 is emptybr; } If you leave the text box empty (empty!) then this will be true. If you type anything into the box, then this will come out false. if (isset($_POST['q2'])){ print Value of q2 == .$_POST['q2'].br; } Now... ! checkboxes and radio buttons are a whole different entity. If you don't select a radio option or check a checkbox, then the variable is _never set_ at all. So $_POST['q2'] does not exist in your script, because nothing was selected. So isset() is going to fail. if (empty($_POST['q2'])){ print q2 is emptybr; } Now, this is going to come out true, although it really shouldn't. Technically the variable is empty, because it doesn't exist. The manual says no warning is generated when the variable is not set if (isset($_POST['q3'])){ print Value of q3 == .$_POST['q3'].br; } if (empty($_POST['q3'])){ print q3 is emptybr; } Same as above, an unchecked checkbox will cause this variable to never be created, so it's not set and it's empty. if (isset($_POST['q4'])){ print Value of q4 == .$_POST['q4'].br; } if (empty($_POST['q4'])){ print q4 is emptybr; } There is no 'q4' in your form. You did this on purpose, right? It's going to come out the same way as 'q2' and 'q3', it doesn't exist. So it's not set and it's empty. Hope that clears some things up. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] empty and isset
Belay that one. I figured it out. My err. I will shut up and go back to lurk mode. So sorry, please don't flog me. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php