我一直跑进一个空白页面!每当我尝试访问该网站时,它都是空白的!这应该是一个简单的SQL检索页面(https://www.youtube.com/watch?v=IYmS5HRo6JI),但它只是不起作用。有什么想法吗?
<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="name">Name</option>
<option value="date">Date</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 calls WHERE $category = '$category'";
$result = mysqli_query($dbcon, $query) or die ('Error');
echo "<table>";
echo "<tr> <th>Date</th> <th>Name</th>";
}
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo "<tr><td>";
echo $row ['date'];
echo "<tr><td>";
echo $row ['name'];
}
?>
</body>
</html>
答案 0 :(得分:0)
我完全删除了
<style...
从头部开始显示。
以下是我使用的正确显示的完整代码:
<html>
<head>
<title>Search</title>
</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="name">Name</option>
<option value="date">Date</option>
</select>
</label>
<label>Search Criteria: <input type="text" name="criteria" /></label>
<input type="submit" />
</form>
</body>
</html>
答案 1 :(得分:0)
这应该有效。仔细看看* mysqli_num_rows *。
<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="name">Name</option>
<option value="date">Date</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 calls WHERE $category = '$category'";
$result = mysqli_query($dbcon, $query) or die ('Error');
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>Date</th>";
echo "<th>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['date'] . "</th>";
echo "<th>" . $row['name'] . "</th>";
echo "</tr>";
}
}
echo "</tbody>";
echo "</table>";
}
?>
</body>
</html>