[UPHPU] Newbie needs help

Saint Chaos saintchaos at gmail.com
Fri Jun 10 11:17:41 MDT 2005


> Here is what I have in my php file now (anyone see any
> syntax problems there?)....
>
> <?php
> $name = $_REQUEST['name'];
> if (!isset($name))  {
> ?>
> <!-- No name has been provided, so we
>  prompt the user for one.       -->
>
> <form action="<?=$_SERVER["PHP_SELF"]?>"
> method="post">
> Please enter your name: <input type="text" name="name"
> />
> <input type="submit" value="GO" />
> </form>
>
> <?php } else  { ?>
> <p>Your name: <?=$name?></p>
>
> <p>This paragraph contains a <a
> href="newpage.php?name=<?=urlencode($name)?>">link</a>
> that passes the name variable on to the next
> document</p>
>
> <?php } ?>

It's your (!isset($name)) string that is failing. isset does not check
to see if your variable has a valid constant or not, it only checks to
see if $name exists and has a constant other than 'null' (which we do
not in this case, we have an empty string but it is not the same as a
PHP null).

You can either use:
if (empty($name))
or
if (!define($name))
to make sure there is a valid constant assigned to the variable,
either of these should repeat your name box if nothing was entered the
first time around.

Regards,
Shaun Gillespie

(One of these days I will remember that I have to include the UPHPU
mailing list on my replies <sigh>)




More information about the UPHPU mailing list