こんにちは、私の課題のこのタスクで大きな問題が発生しています
私は xampp に search_test という名前のデータベースをセットアップしました。このデータベースには、名前と姓がフィールドとして含まれています。私は php フォームを設定したので、ユーザーが Andre という名前を入力すると、データベース内のすべての andres が返されます。データベースにデータがあることを知っていても、検索結果がないという問題があります。これは、index.php と呼ばれる 1 つの php ページであるはずのコードです。
<?php
mysql_connect("localhost","michael","xcA123sd") or die(mysql_error());
mysql_select_db("search_test") or die ("could not find db");
$output ='';
if (isset ($_POST['search']));
$searchq = $_POST['search'];
$query = mysql_query("SELECT * FROM members WHERE firstname LIKE '%searchq%'" ) or die("could not search");
$count = mysql_num_rows($query);
if($count == 0){
$output = 'There was no search results !';
}else{
while($row = mysql_fetch_array($query)){
$fname = $row['firstname'];
$output .='<div> '.$fname.'</div>';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>search</title>
</head>
<body>
<form action="index.php" method="post">
<input type="text" name="search" placeholder="search for members"/>
<input type="submit" value=">>"/>
</form>
<?php print("$output);?>
</body
</html>
たとえば、andre と入力すると、応答が返されます
検索結果はありませんでした。
誰か助けてくれませんか