isset() driving me crazy
Posted: Thu Sep 30, 2010 7:47 am
I have a very simple script using isset() and the logic just does not work using PHP 5.3.1 and 5.2.9 on my localhost and website respectively.
Whatever I do, isset() always seems to return true.
I am new to PHP programming but otherwise not a beginning programmer but I presume I must be making a beginners mistake though am following an example from a book on PHP.
Can anyone help?
The html code and php script are:
<form action="form.php" method="post">
<fieldset><legend>Enter Name:</legend>
<p><b>Name:</b>
<input type="text" name="name" size="20" maxlength="40" /></p>
</fieldset>
<input type="submit" name="submit" value="Submit" />
</form>
// file form.php
<?php
$name = NULL;
$name = $_REQUEST['name'];
if (isset($name))
{
echo '<p>isset was true for $name</p>';
}
else
{
echo '<p>isset was false for $name</p>';
}
?>
Whatever I do, isset() always seems to return true.
I am new to PHP programming but otherwise not a beginning programmer but I presume I must be making a beginners mistake though am following an example from a book on PHP.
Can anyone help?
The html code and php script are:
<form action="form.php" method="post">
<fieldset><legend>Enter Name:</legend>
<p><b>Name:</b>
<input type="text" name="name" size="20" maxlength="40" /></p>
</fieldset>
<input type="submit" name="submit" value="Submit" />
</form>
// file form.php
<?php
$name = NULL;
$name = $_REQUEST['name'];
if (isset($name))
{
echo '<p>isset was true for $name</p>';
}
else
{
echo '<p>isset was false for $name</p>';
}
?>