Reply to Re: Complete newbie looking for a little help

Your name:

Reply:


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

[Back to original 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

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация