php - $_GET undefined index radio button
im doing ORDER BY list by using radio button and then submit.
im stuck in this code, it works fine when i submit but there's an error message undefined index whenever i check and submit the Pending radio button. the $limit variable is just the limit of list per page.
PHP
$limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$sql = "SELECT * FROM v_tickets_information";
if (!isset($_GET['filter'])) {
if ($_GET['filter'] == 'old') {
$sql .= " ORDER BY Date_Time ASC $limit";
} elseif ($_GET['filter'] == 'latest') {
$sql .= " ORDER BY Date_Time DESC $limit";
} elseif ($_GET['stats'] == 'pending') {
$sql .= " WHERE TicketStatus = 'Pending' ORDER BY Date_Time DESC $limit";
}
}
HTML
<form>
<input type="radio" name="filter" value="latest"> Latest to old<br>
<input type="radio" name="filter" value="old"> Old to latest<br>
<hr>
<input type="radio" name="stats" value="new"> New<br>
<input type="radio" name="stats" value="pending"> Pending<br>
<input type="radio" name="stats" value="open"> Open<br>
<input type="radio" name="stats" value="closed"> Closed
<div >
<label for="dept"><h2>Department</h2></label>
<select id="dept" name="dept">
<option>All</option>
<option>Accounting</option>
<option>Admin Office</option>
<option>Customer Service</option>
<option>SLI</option>
<option>HRD</option>
<option>Engineering Office</option>
<option>Production</option>
<option>Accounting</option>
<option>IMPEX</option>
<option>MIS</option>
</select><br>
<div >
<input type="submit" name="Submit" value="Sort" />
</div>
</div>
</form>
btw i didnt create a code php for department cause im getting early error i have to fix this first. help me please fix this code. Heres the screenshot. screenshot image
Answer
Solution:
Try replacing your statements with those