Learning PHP and MySQL
Example 10-02 Modifying our simple search to process the results
<html>
<head>
<title>Building a Form</title>
</head>
<body>
<?php
$search = $_GET["search"];
$self=$_SERVER['PHP_SELF'];
if ($search != NULL )
{
echo "The search string is: <strong>$search</strong>.";
}
else
{
('
<form action="'.$_SERVER["PHP_SELF"].'" method="GET">
<label>Search: <input type="text" name="search" />
</label>
<input type="submit" value="Go!" />
</form>
');
}
?>
</body>
</html>
The above code generates:
<html>
<head>
<title>Building a Form</title>
</head>
<body>
<form action="/oreilly/ch10/simple.php" method="GET" />
<label> Search: <input type="text" name="search" id="search"> </label>
<input type="submit" value="Go!" />
</form>
</body>
</html>
Posted by on 08/18 at 10:52 AM
I couldn’t get the example from the book to work, so I found this site and noticed you modified it here with an if then loop. Still wouldn’t work. After much messing around, I found the problem: you forget “echo” before the (’ at the beginning of the form both here and in the book.
Posted by on 07/16 at 07:03 PM
Page 1 of 1 pages
Next entry: Example 10-03 Form default values
Previous entry: Example 10-01 A simple form example