| Can't get empty $ GET
|
RammsteinNicCage

msg:4487815 | 11:54 pm on Aug 23, 2012 (gmt 0) | I'm having trouble getting some code to work properly. Here's an example of my code:
$a = $_GET['a']; $b = $_GET['b']; $c = $_GET['c']; $d = $_GET['d']; $e = $_GET['e'];
if (empty ($e) { echo "e is empty"; }
If I type in example.com/file.php?a=1&b=2&c=3&d=4&e= the echo is executed. I've tried doing this on different variations (empty, !empty, isset, !isset, etc) and cannot manage to get the echo to not execute. I did a vars dump and for the last variable, it said something like string(0) "" Ideally, I'd like to test to see if each variable is empty, but I figured that'd be easy once I figure out how to get one of them to work.... Can someone please let me know what I am doing wrong and if there is a better way to do it? Even if there is a better way, I would like to know what am I missing when trying to do it this way.... Thanks for the help!
|
jbroder

msg:4487828 | 12:53 am on Aug 24, 2012 (gmt 0) | Reading the empty function info on php.net it seems empty is true if the variable doesn't exist or the value of the variable = false. Your var dump indicates the variable e exists (it is a string with no date in it) so it is set (isset won't work). How about use this? if ($e == '') { echo 'e is blank'; }
|
RammsteinNicCage

msg:4487841 | 1:52 am on Aug 24, 2012 (gmt 0) | Do I need a double quote on that?
|
cffrost2

msg:4487869 | 4:16 am on Aug 24, 2012 (gmt 0) | You didn't properly close your if statement befor you started the code block. Should be if (empty ($e)) { I use a little different approach. Try this.
if(isset($_GET['e']) and $_GET['e'] != '') { $e = $_GET['e']; } else { $e = 'e is empty'; } echo $e; Here you are checking that the e var is set and that it doesn't equal nothing. Hope this helps. There are a lot of different ways to do what you're wanting. This is just one easy way.
|
|
|