-3

データベースには接続できますが、検索クエリの結果が表示されません。「学生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>

助けてくれてありがとう!〜カーペットフィズ

4

1 に答える 1

2

クエリにタイプミスが$criteraあります。意図した場所にあります$criteria

$query = "SELECT * FROM student_info WHERE $category = '$critera'";
                                     YOU LACK AN i HERE -------^
于 2013-04-27T16:51:34.217 に答える