Welcome to WebmasterWorld Guest from 54.198.108.19

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Can't get empty $ GET

     
11:54 pm on Aug 23, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:May 20, 2003
posts: 493
votes: 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!
12:53 am on Aug 24, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 3, 2007
posts: 61
votes: 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'; }
1:52 am on Aug 24, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:May 20, 2003
posts: 493
votes: 0


Do I need a double quote on that?
4:16 am on Aug 24, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:June 6, 2006
posts:103
votes: 2


You didn't properly close your if statement befor you started the code block.
if (empty ($e) {

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.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members