You are here: Re: [newbie] IsSet() tricky to use? « PHP Programming Language « IT news, forums, messages
Re: [newbie] IsSet() tricky to use?

Posted by Kim Andrι Akerψ on 02/08/07 04:14

Vincent Delporte wrote:

> On Thu, 08 Feb 2007 01:30:07 +0100, Rik <luiheidsgoeroe@hotmail.com>
> wrote:
> > While setting a variable to NULL will indeed return false with
> > isset(), the postfields are there. You're looking for empty()
> > instead of isset().
>
> That did the trick, but why is isset() returning true even when I
> leave a field empty in a form?

Simply because the field IS set, even though it's empty.

The isset() function checks if the provided variable exists, but it
doesn't check the contents. On the other hand, empty() checks the
contents of the provided variable, but doesn't first check if it
exists. Using empty() without checking the variable with isset() might
trigger a warning message on some systems. ("Variable not set")

For a more "foolproof" method:

$login = (isset($_POST["login"]) and !empty($_POST["login"])) ?
$_POST["login"] : NULL;

--
Kim AndrΓ© AkerΓΈ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация