I am creating a daycare student registration system. I have a form which submits data into my daycare table. I have a column named Grade and I would like to retrieve all students based on the selected grade. Can anyone assist me in constructing the proper logic to do this? Thanks
Here is my HTML code
<form method="POST" action="display.php">
View Student Records
<select name="grades">
<option value="all">All</option>
<option value="3">3rd Grade</option>
<option value="4">4th Grade</option>
<option value="5">5th Grade</option>
<option value="6">6th Grade</option>
</select>
<input type="submit" value="View Students" name="view">
</form>
PHP code this is my attempted logic if the user selects 3rd graders. my grade field is also a text format rather than number
<?php
session_start();
require("dbconnect.php");
if(empty($_SESSION['user_name']))
{
echo "Please login: <a href='./index.php>Login</a>";
exit();
}
?>
<?php
$link=Connect();
if (isset($_POST['view'])){
$grade = ($_POST['grades']);
$select = "SELECT * daycare WHERE Grade = $grade";
$result = mysql_connect($select, $link) or die("Error: "mysql_error());
}
echo "<table>";
while($row = mysql_fetch_array($select){
echo "<tr><td>" . $row['fname'] . "</td><td>" . $row['lname'] . "</td></tr>" . "</td><td>" . $row['grade'] . "</td></tr>";
}
echo "</table>";
}
mysql_close();
?>