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!

<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">
<br />


$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

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

$rs = $conn->Execute($selectCommand);

//opens a recordset from the connection object

if (!$rs->EOF){


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



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


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


Answer Source


$searchquery = $_GET ('search');


$searchquery = $_GET['search'];

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