Computing.Net > Forums > Web Development > php forms

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

php forms

Reply to Message Icon

Name: studix
Date: June 8, 2005 at 07:58:12 Pacific
OS: xp
CPU/Ram: pentium M 512mb
Comment:

HI there, im begining to learn php. Im a total beginer, so please excuse the easy questions. ive got a simple form and im trying to construct an if statement to test if its been filled. This is wat ive got
<?php
$name=$_GET['myname'];

if (isset($name))
{echo 'True';}
else
{echo 'false';}
?>

I tryed more complex things however true will still be shown reguardless of the contenet of the feild. Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: SN
Date: June 8, 2005 at 10:38:41 Pacific
Reply:

My guess is that when you make the assignment $name = $_GET['myname'], $name becomes set (even if $_GET['myname'] wasn't set, so isset($name) will always return true.

This is what you mean:
if (isset($_GET['myname']))
echo 'True';
else
echo 'False';


0

Response Number 2
Name: jam14online
Date: June 9, 2005 at 03:28:01 Pacific
Reply:

Alternatively, you could use if(!empty($_GET["myname"])), although it's more messy and contradicting.

Whatever's easier for you, though.


0

Response Number 3
Name: fambi
Date: June 13, 2005 at 10:17:44 Pacific
Reply:

Similar to James, i most often use

if($_GET[myname]=="")

But it comes down to individual preference.

Looking for a bulk sms gateway or just want to send sms? Let me know, that's what i do!


0

Response Number 4
Name: Laler
Date: June 14, 2005 at 09:28:17 Pacific
Reply:

I think isset() is best, because if you use if (!empty ($_GET)) then when there's no $_GET set, an "undefined variable" notice will show up. Same with directly testing if ($_GET['name'] == '').

And ignoring notices is not a good practice.


0

Response Number 5
Name: Laler
Date: June 14, 2005 at 09:30:11 Pacific
Reply:

On a second thought, I think empty() will check if it's: NULL, '', or not set... so using empty() is fine I guess :P


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

Repeating information on ... XP home web servers (free...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: php forms

PHP Form www.computing.net/answers/webdevel/php-form/2146.html

php forms help www.computing.net/answers/webdevel/php-forms-help/2224.html

php form www.computing.net/answers/webdevel/php-form/2824.html