NHStars Posted December 14, 2006 Share Posted December 14, 2006 I'm working on a code to validate some data through a post form...my problem is that I'm trying to figure out if both of my variables are empty or not.it's basically something like this[color=red]$ef = $_POST['f'];$es = $_POST['s'];if (!$ef [color=green]AND[/color] !$es) {code here blah blah}[/color]Being that I come from a background of Visual Basic programming, I figured I'd try this. Now I can't seem to find out what the PHP equivalent is. Same with OR in place of AND. Anything you guys can tell me is appreciated. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/30584-andor-operators/ Share on other sites More sharing options...
hitman6003 Posted December 14, 2006 Share Posted December 14, 2006 [code]if ($ef == "" && $es == "") {[/code] Link to comment https://forums.phpfreaks.com/topic/30584-andor-operators/#findComment-140826 Share on other sites More sharing options...
ToonMariner Posted December 14, 2006 Share Posted December 14, 2006 when posting forms all the fields (except unchecked radio buttons/checkboxes are set - even if they are null or empty.you best option is if (empty($ef) && empty($es)).... Link to comment https://forums.phpfreaks.com/topic/30584-andor-operators/#findComment-140831 Share on other sites More sharing options...
SharkBait Posted December 14, 2006 Share Posted December 14, 2006 [code]<?phpif(empty($ef) || empty($es)) { // Do stuff}?>[/code] Link to comment https://forums.phpfreaks.com/topic/30584-andor-operators/#findComment-140870 Share on other sites More sharing options...
kenrbnsn Posted December 14, 2006 Share Posted December 14, 2006 The problem with checking to see if the field is empty with the empty() function is that if the field contains the single character "0" the function emtpy() will return "true". I use the following to see if the field is emty:[code]<?phpif (strlen(trim(stripslashes($_POST['fld']))) == 0) echo 'The field is emtpy';?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/30584-andor-operators/#findComment-140882 Share on other sites More sharing options...
SharkBait Posted December 14, 2006 Share Posted December 14, 2006 Oh I like that, think I'll use that from now on. Link to comment https://forums.phpfreaks.com/topic/30584-andor-operators/#findComment-140885 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.