|
Posted by Mike P2 on 05/09/07 23:20
On May 9, 7:10 pm, DeanL <deanpmlonghu...@yahoo.com> wrote:
> <html>
> <head>
> <title>Building a Form</title>
> </head>
> <body>
> <?php
> $search = $_GET["search"];
> $self=$_SERVER['PHP_SELF'];
> if ($search != NULL )
> {
> ('
> <form action="'.$_SERVER["PHP_SELF"].'" method="GET">
> <label>Search: <input type="text" name="search" />
> </label>
> <input type="submit" value="Go!:" />
>
> </form>
> ');}
>
> ?>
> </body>
> </html>
That's some pretty strange code. When was this book published?
Whether or not that array index is set should be checked before use,
try this instead:
<html>
<head>
<title>Building a Form</title>
</head>
<body>
<?php
$self = '';
if( isset( $_SERVER['PHP_SELF'] )
{
$self = $_SERVER['PHP_SELF'];
}
if( isset( $_GET["search"] ) )
{
echo "
<form action="$self" method='get'>
<label for='search'>Search:</label>
<input type='text' name='search' id='search' />
<input type='submit' value='Go!' />
</form>";
}
?>
</body>
</html>
This will accomplish what it looks like the book is trying to do,
however I don't see why you would do that. It will only display the
search form if the form was already submitted. To show the form, you
would need to type in whatever.php?search=yep or something instaed of
just whatever.php. Perhaps the book means to /hide/ the form if it was
submitted, in which case you can change this:
if( isset( $_GET['search'] ) )
To this:
if( !isset( $_GET['search'] ) )
Good luck,
Mike PII
Navigation:
[Reply to this message]
|