我正在设计一个网站与搜索栏进入查询。但是,每当我输入一个查询时,就会得到一个空白页。
在index.php中,我有:
<?php
include_once('search.php');
?>
<head>
<title>Search</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<form method="POST" action="search.php">
<input type="text" name="q" placeholder="Enter query"/>
<input type="submit" name="search" value="Search" />
</form>
</body>
在search.php中
<?php
include_once('db.php'); //Connect to database
if(isset($_POST['search'])){
$q = $_POST['q'];
$query = mysqli_query($conn, "SELECT * FROM 'words' WHERE 'englishWord' LIKE '%$q%'");
$count = mysqli_num_rows($query);
if($count == "0"){
$output = '<h2>No result found</h2>';
}else{
while($row = mysqli_fetch_array($query)){
$s = $row['yupikWord']; //column of results
$output .= '<h2>'.$s.'</h2><br>';
}
}
}
echo $output;
mysqli_close($conn);
?>
在db.php中
<?php
$servername = "localhost";
$username = "qaneryararvik";
$password = "PASSWORD";
$database = "yupik";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
$dbcon = mysqli_select_db($conn,$database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully<br>";
我可以在搜索框中输入文本,然后单击“搜索”按钮。当我点击“搜索”时,我得到的只是一个空白页面,上面写着“连接成功”。查询结果不显示。我做错什么了?
2条答案
按热度按时间cedebl8k1#
在search.php中
lmvvr0a82#
报价是错误的。对于表和行,应为“而不是”: