时间:2021-07-01 10:21:17 帮助过:8人阅读
- <!--
- Code highlighting produced by Actipro CodeHighlighter (freeware)
- http://www.CodeHighlighter.com/
- -->
- catalog search
- <h2>catalog search</h2>
- <!--
- Code highlighting produced by Actipro CodeHighlighter (freeware)
- http://www.CodeHighlighter.com/
- -->
- <h2>search results</h2>
- <!--?php
- $searchtype=$_POST['searchtype'];
- $searchterm=trim($_POST['searchterm']);
- if(!$searchtype||!$searchterm){
- echo"请输入值";
- exit;
- }
- if(!get_magic_quotes_gpc())
- {
- $searchtype=addslashes($searchtype);
- $searchterm=addslashes($searchterm);
- }
- @ $db=new mysqli('localhost','root','root','books');
- if (mysqli_connect_errno())
- {
- echo 'Error: Could not connect to database. Please try again later.';
- exit;
- }
- $query="select * from books where".$searchtype."like '%".$searchterm."%'";
- $result=$db--->query($query);
- $num_results=$result->num_rows;
- echo "<p>Number of books found:".$num_results."</p>";
- for ($i=0;$i<$num_results;$i++)
- {
- $row=$result->fetch_assoc();
- echo"<p><strong>".($i+1)."title:";
- echo htmlspecialchars(stripslashes($row['title']));
- echo "</strong><br>author:";
- echo stripslashes($row['author']);
- echo"<br>isbn:";
- echo stripslashes($row['isbn']);
- echo"<br>price:";
- echo stripslashes($row['price']);
- echo"</p>";
- }
- ?>