RE: [PHP] empty variables from a form
- Original Message - From: Erich Beyrent [EMAIL PROTECTED] To: Sunfire [EMAIL PROTECTED] hi.. how would you test for an empty (unused) variable from a form.. i have a phone number split into 3 different vairiables and want to test to see if they were used in the form before displaying either the phone number itself or just leaving it out of the display... what code would be good to test it with.. the variables are $ac2 $ext2 and $num2 Use the isset() function: if(isset($ac2)) and if(isset($ext2)) and if(isset($num2)) { do something } else { do something else } Eesh! I think you mean: if (isset($ac2) isset($ext2) isset($num2)) { do something } And, depending on what sort of form field it is, isset() might not be a very good test anyway! 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 variables from a form
how would you test for an empty (unused) variable from a form.. i have a phone number split into 3 different vairiables and want to test to see if they were used in the form before displaying either the phone number itself or just leaving it out of the display... what code would be good to test it with.. the variables are $ac2 $ext2 and $num2 umm i don't know maybe empty() ? www.php.net/empty ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] empty variables from a form
Next time please consider searching on PHP.net or Google before you post. This is an exceedingly basic question and there is an extraordinary amount of information already out there.. if(empty($_POST['ac2'])) { echo Area Code is a required field.; } -Kevin - Original Message - From: Sunfire [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, February 05, 2003 11:49 AM Subject: [PHP] empty variables from a form hi.. how would you test for an empty (unused) variable from a form.. i have a phone number split into 3 different vairiables and want to test to see if they were used in the form before displaying either the phone number itself or just leaving it out of the display... what code would be good to test it with.. the variables are $ac2 $ext2 and $num2 --- 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 variables from a form
tnx will try that my other code looked something like that but it didnt work.. probably had the (and ) in the wrong places... i set it up as the whole statement as 1 if statement not 3 different ones.. - Original Message - From: Erich Beyrent [EMAIL PROTECTED] To: Sunfire [EMAIL PROTECTED] Sent: Wednesday, February 05, 2003 1:54 PM Subject: Re: [PHP] empty variables from a form hi.. how would you test for an empty (unused) variable from a form.. i have a phone number split into 3 different vairiables and want to test to see if they were used in the form before displaying either the phone number itself or just leaving it out of the display... what code would be good to test it with.. the variables are $ac2 $ext2 and $num2 Use the isset() function: if(isset($ac2)) and if(isset($ext2)) and if(isset($num2)) { do something } else { do something else } -Erich- --- 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 variables from a form
FYI, isset() will return true for an empty variable. You use isset() only when you expect there to be no variable. But for a hard coded HTML form the variable will *always* be set (except in the case of check boxes) even if thas no value. So your only options are to use empty() or test the string against the litteral expression. if($myvar == ''); ..or.. if(empty($myvar)); -Kevin - Original Message - From: Sunfire [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, February 05, 2003 12:40 PM Subject: Re: [PHP] empty variables from a form tnx will try that my other code looked something like that but it didnt work.. probably had the (and ) in the wrong places... i set it up as the whole statement as 1 if statement not 3 different ones.. - Original Message - From: Erich Beyrent [EMAIL PROTECTED] To: Sunfire [EMAIL PROTECTED] Sent: Wednesday, February 05, 2003 1:54 PM Subject: Re: [PHP] empty variables from a form hi.. how would you test for an empty (unused) variable from a form.. i have a phone number split into 3 different vairiables and want to test to see if they were used in the form before displaying either the phone number itself or just leaving it out of the display... what code would be good to test it with.. the variables are $ac2 $ext2 and $num2 Use the isset() function: if(isset($ac2)) and if(isset($ext2)) and if(isset($num2)) { do something } else { do something else } -Erich- --- 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 variables from a form
hi i tried the code below as well as empty and isset and it seems that even if the variables that have valid data in them they also get excluded from display with the empty ones.. does mean any string? or is it the normal empty string? i need to know if the vars that dont get filled in from the form are empty or not... and this isnt working very will... any idea why this happens? ps if i put or between if statements it gives me a parse error... - Original Message - From: Sunfire [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, February 05, 2003 2:40 PM Subject: Re: [PHP] empty variables from a form tnx will try that my other code looked something like that but it didnt work.. probably had the (and ) in the wrong places... i set it up as the whole statement as 1 if statement not 3 different ones.. - Original Message - From: Erich Beyrent [EMAIL PROTECTED] To: Sunfire [EMAIL PROTECTED] Sent: Wednesday, February 05, 2003 1:54 PM Subject: Re: [PHP] empty variables from a form hi.. how would you test for an empty (unused) variable from a form.. i have a phone number split into 3 different vairiables and want to test to see if they were used in the form before displaying either the phone number itself or just leaving it out of the display... what code would be good to test it with.. the variables are $ac2 $ext2 and $num2 Use the isset() function: if(isset($ac2)) and if(isset($ext2)) and if(isset($num2)) { do something } else { do something else } -Erich- --- 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 --- 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 variables from a form
how would you test for an empty (unused) variable from a form.. i have a phone number split into 3 different vairiables and want to test to see if they were used in the form before displaying either the phone number itself or just leaving it out of the display... what code would be good to test it with.. the variables are $ac2 $ext2 and $num2 Use the isset() function: if(isset($ac2)) and if(isset($ext2)) and if(isset($num2)) { do something } else { do something else } That's not a good idea if your trying to check for an empty variable. An empty text box, when submitted, will still be set and pass isset(). You should use empty() is that's really what you're looking for. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] empty variables from a form
empty doesnt work either... it still comes up as though something is in them and excludes either nothing at all or includes everything...even the empty vars..any reason for that ? - Original Message - From: 1LT John W. Holmes [EMAIL PROTECTED] To: Sunfire [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, February 05, 2003 2:43 PM Subject: Spam: Re: [PHP] empty variables from a form how would you test for an empty (unused) variable from a form.. i have a phone number split into 3 different vairiables and want to test to see if they were used in the form before displaying either the phone number itself or just leaving it out of the display... what code would be good to test it with.. the variables are $ac2 $ext2 and $num2 Use the isset() function: if(isset($ac2)) and if(isset($ext2)) and if(isset($num2)) { do something } else { do something else } That's not a good idea if your trying to check for an empty variable. An empty text box, when submitted, will still be set and pass isset(). You should use empty() is that's really what you're looking for. ---John Holmes... -- 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: Re: [PHP] empty variables from a form
On Thursday 06 February 2003 05:10, Sunfire wrote: empty doesnt work either... it still comes up as though something is in them and excludes either nothing at all or includes everything...even the empty vars..any reason for that ? Do var_dump() all the vars which you think are empty but PHP thinks otherwise. -- 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 face of war has never changed. Surely it is more logical to heal than to kill. -- Surak of Vulcan, The Savage Curtain, stardate 5906.5 */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] empty variables from a form
Okay enough of this. Please show us some code. :-) -Kevin - Original Message - From: Sunfire [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, February 05, 2003 2:10 PM Subject: Re: Re: [PHP] empty variables from a form empty doesnt work either... it still comes up as though something is in them and excludes either nothing at all or includes everything...even the empty vars..any reason for that ? - Original Message - From: 1LT John W. Holmes [EMAIL PROTECTED] To: Sunfire [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, February 05, 2003 2:43 PM Subject: Spam: Re: [PHP] empty variables from a form how would you test for an empty (unused) variable from a form.. i have a phone number split into 3 different vairiables and want to test to see if they were used in the form before displaying either the phone number itself or just leaving it out of the display... what code would be good to test it with.. the variables are $ac2 $ext2 and $num2 Use the isset() function: if(isset($ac2)) and if(isset($ext2)) and if(isset($num2)) { do something } else { do something else } That's not a good idea if your trying to check for an empty variable. An empty text box, when submitted, will still be set and pass isset(). You should use empty() is that's really what you're looking for. ---John Holmes... -- 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] empty variables from a form
empty doesnt work either... it still comes up as though something is in them and excludes either nothing at all or includes everything...even the empty vars..any reason for that ? Because you're jacking something up in your logic or code... show us how your trying to solve this perplexing dilemma (show us your code). ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php