I am having trouble with getting the radio buttons to work with my select statement the issue lies somewhere in the buttons i think but i am unsure of this any and all help is appreciated
here is the code that i have currently. what i need to happen is for the page to refresh and sort the table to what has been selected by the button
<?php require_once('dbadmin.php');?>
<?php
session_start();
$user = $_SESSION['user'];
if(!isset($user)){
header("Location:admin_login.php");
}
?>
<h1>Reports</h1>
<table border="1" style="width:100%">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Distance</th>
</tr>
<?php
include('dbadmin.php');
$select = "SELECT `fname`, `lname`, `email`, `distance` FROM runner ORDER BY `lname`";
$result = mysql_query($select) or die ('Oops! '.mysql_error($connect));
if(isset($_POST['submit_sort'])){
$radio = $_POST['radiosort'];
if($radio =='fname'){
$select = "SELECT `fname`, `lname`, `email`, `distance` FROM runner ORDER BY `fname`";}
else if($radio =='lname'){
$select = "SELECT `fname`, `lname`, `email`, `distance` FROM runner ORDER BY `lname`";}
else if($radio =='distance'){
$select = "SELECT `fname`, `lname`, `email`, `distance` FROM runner ORDER BY `distance`";}
$result = mysql_query($select) or die("Invalid query: ".mysql_error($connect));
}
if (mysql_num_rows($result) > 0) {
while($row = mysql_fetch_assoc($result)) {
echo '<tr><td>'.$row['fname'].'</td>';
echo '<td>'.$row['lname'].'</td>';
echo '<td>'.$row['email'].'</td>';
echo '<td>'.$row['distance'].'</td></tr>';
}
}
?>
<form name="reports" id="reports" action="reports.php">
<label for="submit_sort" style="font-weight:bold;">Sort By:</label><br>
<input name="radiosort" type="radio" title="sort" id="lname" value="lname">
<label for="lname">Last Name</label><br>
<input name="radiosort" type="radio" title="sort" id="fname" value="fname">
<label for="fname">First Name</label><br>
<input name="radiosort" type="radio" title="sort" id="distance" value="distance">
<label for="distance">Distance</label><br><br>
<input type="submit" name="submit_sort" title="submit_sort" id="submit" value="Submit">
</form>
</table>