我能够连接到数据库,但是,我无法查看搜索查询的结果。每当我在"学生ID"中输入一个值时,该字段将被删除,并且没有结果显示。在我可能做错的事情上,任何帮助都会受到赞赏。此外,是的,我的SQL表包含所有这些列。
search1.php
<html>
<head>
<title>Student Search</title>
<style type="text/css">
table {
background-color: #FCF;
}
th {
width: 150px;
text-align:left;
}
</style>
</head>
<body>
<h1>Student Search</h1>
<form method = "post" action="search1.php">
<input type="hidden" name="submitted" value="true" />
<label>Student ID:
<select name="category">
<option value="ID">ID</option>
</select>
</label>
<label>Search Criteria: <input type="text" name="criteria"/></label>
</form>
<?php
if (isset($_POST['submitted'])) {
//connect to the database
include ('mcon.php');
$category = $_POST['category'];
$criteria= $_POST['criteria'];
$query = "SELECT * FROM student_info WHERE $category = '$critera'";
$result = mysqli_query($dbcon, $query) or die('Error getting data.');
echo "<table>";
echo "<tr>
<th>ID</th>
<th>Project</th>
<th>Starter Project</th>
<th>Course</th>
<th>KDs Completed in your Course</th>
<th>Projects Completed</th>
<th>Pro
ject 1</th>
<th>P1KD1</th>
<th>P1KD2</th>
<th>P1KD3</th>
<th>P1KD4</th>
<th>P1KD5</th>
<th>Project 2</th>
<th>P2KD1</th>
<th>P2KD2</th>
<th>P2KD3</th>
<th>P2KD4</th>
<th>P2KD5</th>
<th>Project 3</th>
<th>P3KD1</th>
<th>P3KD2</th>
<th>P3KD3</th>
<th>P3KD4</th>
<th>P3KD5</th>
<th>Project 4</th>
<th>P4KD1</th>
<th>P4KD2</th>
<th>P4KD3</th>
<th>P4KD4</th>
<th>P4KD5</th>
</tr>";
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo "<tr><td>";
echo $row['ID'];
echo "</td><td>";
echo $row['Project'];
echo "</td><td>";
echo $row['Starter Project'];
echo "</td><td>";
echo $row['Course'];
echo "</td><td>";
echo $row['KDs completed in your course'];
echo "</td><td>";
echo $row['Projects Completed'];
echo "</td><td>";
echo $row['Project 1'];
echo "</td><td>";
echo $row['P 1 K D 1'];
echo "</td><td>";
echo $row['P 1 K D 2'];
echo "</td><td>";
echo $row['P 1 K D 3'];
echo "</td><td>";
echo $row['P 1 K D 4'];
echo "</td><td>";
echo $row['P 1 K D 5'];
echo "</td><td>";
echo $row['Project 2'];
echo "</td><td>";
echo $row['P 2 K D 1'];
echo "</td><td>";
echo $row['P 2 K D 2'];
echo "</td><td>";
echo $row['P 2 K D 3'];
echo "</td><td>";
echo $row['P 2 K D 4'];
echo "</td><td>";
echo $row['P 2 K D 5'];
echo "</td><td>";
echo $row['Project 3'];
echo "</td><td>";
echo $row['P 3 K D 1'];
echo "</td><td>";
echo $row['P 3 K D 2'];
echo "</td><td>";
echo $row['P 3 K D 3'];
echo "</td><td>";
echo $row['P 3 K D 4'];
echo "</td><td>";
echo $row['P 3 K D 5'];
echo "</td><td>";
echo $row['Project 4'];
echo "</td><td>";
echo $row['P 4 K D 1'];
echo "</td><td>";
echo $row['P 4 K D 2'];
echo "</td><td>";
echo $row['P 4 K D 3'];
echo "</td><td>";
echo $row['P 4 K D 4'];
echo "</td><td>";
echo $row['P 4 K D 5'];
echo "</td></tr>";
}
echo "</table>";
} //end of main if statement
?>
</body>
</html>
非常感谢您的帮助! 〜Carpetfizz
答案 0 :(得分:2)
您的查询中有拼写错误,您的$critera
意味着$criteria
,请参阅:
$query = "SELECT * FROM student_info WHERE $category = '$critera'";
YOU LACK AN i HERE -------^