php - $_GET undefined index radio button

884

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

975

Answer

Solution:

if (isset($_GET['filter']) && $_GET['filter'] == 'old') {
    $sql .= " ORDER BY Date_Time ASC $limit";
} elseif (isset($_GET['filter']) && $_GET['filter'] == 'latest') {
    $sql .= " ORDER BY Date_Time DESC $limit";
} elseif (isset($_GET['stats']) && $_GET['stats'] == 'pending') {
    $sql .= " WHERE TicketStatus = 'Pending' ORDER BY Date_Time DESC $limit";
} 

Try replacing your statements with those

People are also looking for solutions to the problem: php - How to parse YouTube video ID?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.