homepage Welcome to WebmasterWorld Guest from 54.166.84.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Can't get empty $ GET
RammsteinNicCage

10+ Year Member



 
Msg#: 4487813 posted 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

5+ Year Member



 
Msg#: 4487813 posted 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

10+ Year Member



 
Msg#: 4487813 posted 1:52 am on Aug 24, 2012 (gmt 0)

Do I need a double quote on that?

cffrost2

5+ Year Member



 
Msg#: 4487813 posted 4:16 am on Aug 24, 2012 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved