wtfsmd Posted March 23, 2009 Share Posted March 23, 2009 How would i get this to work? I don't get any syntax errors it just doesn't want to work. <?php if ( !empty($icq) || !is_null($icq) ) { echo "this"; } ?> Link to comment https://forums.phpfreaks.com/topic/150655-solved-help-with-empty-and-is_null/ Share on other sites More sharing options...
jlhaslip Posted March 23, 2009 Share Posted March 23, 2009 Where do you define (or not) $icq ? Link to comment https://forums.phpfreaks.com/topic/150655-solved-help-with-empty-and-is_null/#findComment-791456 Share on other sites More sharing options...
wtfsmd Posted March 23, 2009 Author Share Posted March 23, 2009 What do you mean? I just want to know if it is not empty or is not null Link to comment https://forums.phpfreaks.com/topic/150655-solved-help-with-empty-and-is_null/#findComment-791461 Share on other sites More sharing options...
jlhaslip Posted March 23, 2009 Share Posted March 23, 2009 Is the variable used in a Form or might it be coming from a DB query? Where is it coming from if it is not null or not empty? is oit an array? Does it simply appear out of thin air? Link to comment https://forums.phpfreaks.com/topic/150655-solved-help-with-empty-and-is_null/#findComment-791469 Share on other sites More sharing options...
wtfsmd Posted March 23, 2009 Author Share Posted March 23, 2009 Sorry i read that wrong It comes out of my MySQl db <?php $query = "SELECT * FROM user WHERE id='$id'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); $icq = $row['icq']; if ( !empty($icq) || !is_null($icq) ) { echo "this"; } ?> Link to comment https://forums.phpfreaks.com/topic/150655-solved-help-with-empty-and-is_null/#findComment-791470 Share on other sites More sharing options...
redarrow Posted March 23, 2009 Share Posted March 23, 2009 do you mean this statement. <?php $a['name']==" "; $a['name']=NULL; if(empty($a['name'])&& is_null($a['name'])){ echo hi; } ?> Link to comment https://forums.phpfreaks.com/topic/150655-solved-help-with-empty-and-is_null/#findComment-791473 Share on other sites More sharing options...
wtfsmd Posted March 23, 2009 Author Share Posted March 23, 2009 do you mean this statement. <?php $a['name']==" "; $a['name']=NULL; if(empty($a['name'])&& is_null($a['name'])){ echo hi; } ?> no not like that, it comes out of my database. I want to know this "if $icq is not empty OR is not null" which is what my statement says. Link to comment https://forums.phpfreaks.com/topic/150655-solved-help-with-empty-and-is_null/#findComment-791481 Share on other sites More sharing options...
trq Posted March 23, 2009 Share Posted March 23, 2009 Your original code works as expected. Obviously $icq isn't what YOU think it is however. Link to comment https://forums.phpfreaks.com/topic/150655-solved-help-with-empty-and-is_null/#findComment-791486 Share on other sites More sharing options...
trq Posted March 23, 2009 Share Posted March 23, 2009 On top of that, empty returns true when its argument is NULL, so theres really no need to check for both. Link to comment https://forums.phpfreaks.com/topic/150655-solved-help-with-empty-and-is_null/#findComment-791488 Share on other sites More sharing options...
wtfsmd Posted March 23, 2009 Author Share Posted March 23, 2009 Your original code works as expected. Obviously $icq isn't what YOU think it is however. I removed the " || !is_null ($icq) " from the statement and it works as expected. When i look at the row in my DB its empty As for the new post i am dumb for not even realizing that empty returns true for null, and that works just fine thanks. Link to comment https://forums.phpfreaks.com/topic/150655-solved-help-with-empty-and-is_null/#findComment-791493 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.