-1
好吧,我可以爲這個最新的問題得到一些明確的答案。這個PHP部分不會返回任何響應,但是,我知道數據在那裏。有誰知道爲什麼這會返回文本「錯誤」?PHP SQL搜索頁面返回錯誤
<html>
<head>
<title>Search</title>
<style type="text/css">
table {
background-color: #FCF;
}
th {
width: 150px;
text-align: left;
}
</style>
</head>
<body>
<h1>Search</h1>
<form method="post" action="search.php">
<input type="hidden" name="submitted" value="true"/>
<label> Search | Category:
<select name="category">
<option value="fname">FName</option>
<option value="lname">LName</option>
</select>
</label>
<label>Search Criteria: <input type="text" name="criteria"/></label>
<input type="submit"/>
</form>
<?php
if (isset($_POST['submitted'])) {
// connect to DB
include('connect.php');
$category = $_POST['category'];
$criteria = $_POST['criteria'];
$query = "SELECT * FROM people WHERE category = '$category'";
$result = mysqli_query($dbcon, $query) or die ('Error');
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>First Name</th>";
echo "<th>Last Name</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
if (mysqli_num_rows($result)) {
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo "<tr>";
echo "<th>" . $row['fname'] . "</th>";
echo "<th>" . $row['lname'] . "</th>";
echo "</tr>";
}
}
echo "</tbody>";
echo "</table>";
}
?>
</body>
</html>
你能指定錯誤是什麼嗎? –
您需要爲數據庫調用添加一些錯誤處理:'或die('Error')' – jeroen