php搜索查询的结果没有显示出来

时间:2022-06-24 05:22:57

I am able to connect to a database, however, I am having trouble seeing the results of the search query. Whenever I enter a value into "Student ID", the field is erased, and no results show. Any help would be appreciated, on what I might have done wrong. Also, yes, my SQL table has all those columns.

我能够连接到数据库,但是,我无法查看搜索查询的结果。每当我在“学生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>

Thanks much for any help! ~Carpetfizz

非常感谢您的帮助! 〜Carpetfizz

1 个解决方案

#1


2  

You have a typo in your query, you have $critera where you meant $criteria see:

你的查询中有一个拼写错误,你有$ critera你的意思是$ criteria见:

$query = "SELECT * FROM student_info WHERE $category = '$critera'";
                                     YOU LACK AN i HERE -------^

#1


2  

You have a typo in your query, you have $critera where you meant $criteria see:

你的查询中有一个拼写错误,你有$ critera你的意思是$ criteria见:

$query = "SELECT * FROM student_info WHERE $category = '$critera'";
                                     YOU LACK AN i HERE -------^