<form action="result.php" method="POST">
<h1>Search</h1>
<input type="text" name="q"></input><br /><br />
<input type="submit" id="submit" value="Search"></input>
</form>
形式
<?php
$servername = "localhost";
$username = "myusername";
$password = "mypassword";
$dbname = "mydb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$mysqli->set_charset("utf8");
if (isset($_REQUEST['q'])){
$target= $_REQUEST['q'];
$sql = " SELECT *
FROM TABLE1
WHERE name
LIKE '%$target%'";
$result = $mysqli->query($sql)
or die($mysqli->error . "<pre>$sql</pre>");
while ($row = $result->fetch_assoc()){
echo $row["number"] . " " . $row["name"]. " " . $row["hp"] . "<br>";
}
}
else {
echo "0 results";
}
?>
result.php
尝试使用搜索查询来显示数据库中的数据。当用户提交表单时,下一页上没有显示任何内容,甚至是其他内容。不确定什么是错的,我正努力在其他线程中找到帮助。感谢。
答案 0 :(得分:1)
您的脚本崩溃了,因为您正在为mysqli连接使用两个不同的变量。
{{1}}