I have a users page, where all the users in the system are displayed by default.
I am trying to apply filters so that users can refine their search for a user. For example, view all users who are male.
By default, to display all users on users.php, I am running this query by default:
$get_all_users = "SELECT * FROM users";
But when a user for example selected they want to view all female users on the system, then I want to run this query (example):
$get_all_users = "SELECT * FROM users WHERE gender = 'female'";
But for some reason, the query which displays all users by default, is always being executed. Here is my approach:
// get gender from radio buttons
$refined_gender = htmlentities (strip_tags(@$_POST['gender']));
$get_all_users = "SELECT * FROM users";
if (isset($_POST['submit'])){
if (isset($_POST['gender'])) {
if ($refined_gender){
$get_all_users = "SELECT * FROM users WHERE gender = '$refined_gender'";
}
}
}
var_dump($_POST)) that those two items are actually set? 2. This probably isn't why it's not working at this point, buthtmlentitiesandstrip_tagsare not suitable for escaping input to an SQL query.@$_POST['gender']is, because of the annoying warning that warned you that this key inside the POST array does not exist. So why not check if beforehand and build your WHERE clause somewhere else where you check (in a switch case) what the user picked in the frontend. 1/2