1
<?php 
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];

if(!$searchtype || !$searchterm)
{ 
echo"you have not entered anything.Pls go back";
exit;
}

if(!get_magic_quotes_gpc())
{ 
  $searchtype=addslashes($searchtype);
  $searchterm=addslashes($searchterm);
}

@$db= new mysqli('localhost','root','mansi','books');
if(mysqli_connect_errno()) 
{ 
echo" Cannot connect to the database";
exit;
}

$query="select * from books where".$serchtype."like '%".$searchterm."%'";
$result=$db->query($query);


$num_results = count($result);

echo"<p>Number of books found:".$num_results."</p>";

     for($i=0;$i<$num_results;$i++)  
 {
      //$row=$result->fetch_assoc();
    $row=mysqli_fetch_assoc($result);

    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>";
}


$db->close();

?>

プログラムは、Title、Author、ISBN、Price などの echo ステートメントを実行して出力しますが、データベースから取得した値を出力しません。プログラムは、$row['title] 、$row['isbn']、$row[ などのクエリの結果を表示できません。 '著者'] と $row['価格'].

データベース名:books. テーブル名も本。

mysql> select * from books;
+-------------+-----------------+-------------------+-------+
| isbn        | author          | title             | price |
+-------------+-----------------+-------------------+-------+
| 0-672       | Michelle Morgan | Java 2 Developers | 38.49 |
| 0-672-31509 | Pruitt          | Teach GIMP        | 27.49 |
| 0-672-31745 | Thomas Down     | Installing Linux  | 27.49 |
| 0-672-31769 | Thomas Schenk   | Caledra           | 54.99 |
+-------------+-----------------+-------------------+-------+
4 rows in set (0.00 sec)
4

1 に答える 1

0

クエリには、「where」の後と「like」の前に余分なスペースが必要です

$query="select * from books where ".$searchtype." like '%".$searchterm."%'";
于 2013-08-09T15:12:51.627 に答える