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. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 14, 2006 Share Posted December 14, 2006 [code]if ($ef == "" && $es == "") {[/code] Quote Link to comment 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)).... Quote Link to comment 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] Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.