So I'm trying to sort an SQL query based on which submit button is clicked
My Sort options:
echo "<form method='post' action adminview.php'>"
."<input type='submit' name='sort' value='Sort by Attempt ID'/><br />"
."<input type='submit' name='sort' value='Sort by Student ID'/><br />"
."<input type='submit' name='sort' value='Sort by lowest Score'/><br />"
."<input type='submit' name='sort' value='Sort by highest Score'/><br />"
."</form>";
And when the page reloads here is the code to check which button was clicked
switch($_POST['sort'])
{
case "Sort by Attempt ID":
$sortby = "attempt_id";
break;
case "Sort by Student ID":
$sortby = "student_id";
break;
case "Sort by lowest Score":
$sortby = "score";
break;
case "Sort by highest Score":
$sortby = "score desc";
break;
}
My issue is that when the page reloads it says that sort is undefined.
If you were curious here is the SQL statement
$sqlstring = "select * from quizattempts order by '$sortby'";
echo '<pre>';print_r($_POST);- this will give you cluedefault:in your switch case.$sqlstring = "select * from quizattempts order by '" . $sortby. "' ";would have probably worked.