How to use searching method using a select tag option to search id,email,username in PHP, MYSQL?

Hello I'm trying to get a searching method using select tag with an option of ID,Email, and Fullname.

I have this html code for search:

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<select class="searchoptionuser" name="Search" id="searchbyuser">
<option value="" disabled selected value>Search User</option>
<option value="ID">ID</option>
<option value="Email">Email</option>
<option value="Fullname">Fullname</option>
<input type="text" name="search" placeholder="Search..." id="search_text" class="searchtext">
<input type="submit" name="submit" value="Search">

And I want to filter the search when I select the ID, the search will only search by ID and also Email and Fullname.

I've tried this in PHP:

include "includes/connection.php";


if(isset($_POST[‘Search’]) == “ID”)
// query code here from database

} else if(isset($_POST[‘Search’]) == “Email”) {
// query code here from database

} else if(isset($_POST[‘Search’]) == “Fullname”) {
// query code here from database
$output = “”;
$sql = “SELECT * FROM user WHERE firstname LIKE '%”.$_POST[“search”].“%’ or lastname LIKE '%”.$_POST[“search”].“%'”;
$result = mysqli_query($connection, $sql);

if (mysqli_num_rows($result) > 0) {
$output .= “<tr><th>User ID</th><th>Email</th><th>Fullname</th><th>Phone Number</th></tr>”;
// output data of each row
while($row = mysqli_fetch_array($result)) {
$output .= “<tr>
<td>” .$row[“id”]. “</td><td>” .$row[“email”]. “</td><td>” .$row[“lastname”]. ", " .$row[“firstname”]. “</td><td>” .$row[“phonenumber”]. “</td>
echo $output;
} else {
echo “No account found.”;


But it doesn’t seem to work… Is this possible in php or this method is only for javascript or jquery. Please help anyone. Thanks

#php #mysql #sql #ajax

4 Likes2.05 GEEK