在表单中显示GET方法的结果

时间:2014-08-20 14:46:49

标签: php forms

我试图在URL中保留查询字符串,以便可以为搜索查询添加书签。当我之前使用" Post"时,正文中会显示相应的内容。表单的操作,但是当我切换到" get"时,内容不会呈现,但查询字符串会显示在URL中。我怎么能两个都做?感谢您对这些人的帮助!

        <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>

2 个答案:

答案 0 :(得分:3)

变化:

$searchquery = $_GET ('search');

要:

$searchquery = $_GET['search'];

答案 1 :(得分:1)

改变这个:

$searchquery = $_GET ('search');

要:

$searchquery = $_GET['search'];