Reply to Re: Complete newbie looking for a little help

Your name:

Reply:


Posted by Mike P2 on 05/09/07 23:42

On May 9, 7:20 pm, Mike P2 <sumguyovrt...@gmail.com> wrote:
> 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

Oops, I forgot to close a parenthesis. Here it is again, even better
this time:

<html>
<head>
<title>Building a Form</title>
</head>
<body>
<?php



if( isset( $_GET['search'] ) )
{
$search = $_GET['search'];

$self = '';

if( isset( $_SERVER['PHP_SELF'] ) )
{
$self = $_SERVER['PHP_SELF'];
}

echo "
<form action='$self' method='get'>
<label for='search'>Search:</label>
<input type='text' name='search' id='search' value='$search' />
<input type='submit' value='Go!' />
</form>";
}

?>
</body>
</html>

Oh yea, and your error message from before was because PHP may or may
not report small errors, depending on the error reporting settings,
and referring to a variable that doesn't exist is considered bad, so
PHP will issue a notice if under the right conditions. That book may
be talking about an older version of PHP that just returned NULL and
ignored the issue, or is assuming that you are using PHP under a
lenient mode.

-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

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