Joe Joe - 4 years ago 111
PHP Question

Display result of GET method in a form

I'm trying to retain the query string in the URL so that the result of a search query can be bookmarked. The appropriate content displays in the body when I previously used the "Post" action for the form, but when I switch to "get", the content does not render, but the query string appears in the URL. How can I do both? Thanks for your help on this folks!

<body>
<div id="wrapper">
<div id="content">
<h1>Search for a book</h1>
<p>You may search by author or title</p>
<form method="GET" action="" >
<input type="text" name="search">
<input type="submit" name="submit" value="Search">
</form>
<br />

<?php


$conn = new COM("ADODB.Connection") or die("Cannot start ADO");

$connString= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\\assignment3.mdb";

//creates the connection object and define the connection string



$conn->Open($connString);
$searchquery = $_GET ('search');
$selectCommand="SELECT * FROM AuthorTitle WHERE title LIKE '%$searchquery%' OR author LIKE '%$searchquery%'";

if(isset($_GET['search'])){
$rs = $conn->Execute($selectCommand);

//opens a recordset from the connection object


if (!$rs->EOF){

$selectCommand=$rs->Fields("ProductID");
$author=$rs->Fields("author");
$title=$rs->Fields("title");

echo "<h1>Search Result for '<b>$searchquery</b>':</h1>
<p><b>$title</b>, $author is available for checkout.</p><br />";

}

else

print "No results found.<br /><br />";



$rs->Close;
}
?>



</div> <!--end content-->
</div> <!--end wrapper-->

</body>
</html>

Answer Source

Change:

$searchquery = $_GET ('search');

To:

$searchquery = $_GET['search'];

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download