|
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]
|