i'm creating a search function with a drop down list where the user can search based on the chosen drop down list and display it on the same page. When I press the submit button, it didn't display any result.
Sorry if this has been asked before, but I suspect there is something that I did wrong at the PHP code but I could not figure out why. Can someone please point it out for me?
This is my search form:
<h2>Search</h2>
<form name="search" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  Keyword  
  <input type="text" name="searchq" id="searchq" size="30" placeholder="Enter keyword..">  By  
  <select name="searchopt" id="searchopt">
    <option value=""></option>
    <option value="Members">Members</option>
    <option value="Journal">Journal</option>
    <option value="Conference">Conference</option>
    <option value="Awards">Awards</option>
    <option value="Grants">Grants</option>
    <option value="Patents">Patents</option>
    <option value="Research Grants">Research Grants</option>
    <option value="Book Chapter">Book Chapter</option>
    <option value="Book Publications">Book Publications</option>
    <option value="Other Publications">Other Publications</option>
  </select>
   
  <input type="submit" id="submit" name="submit" value="Search">
</form>
<br>
<p>
  <h4>Results</h4>
</p>
And this is my PHP code:
include ("includes/dbcon.php");
if(isset($_POST['searchq']) && $_POST['searchq'] != "")
{
    if(isset($_POST['searchopt']) && $_POST['searchopt'] != "")
    {
        $escsearch = mysqli_real_escape_string($conn, $_POST['searchq']);
        $searchval = preg_replace('#[^a-z 0-9]#i', '', $escsearch);
        $opt = $_POST['searchopt'];
        switch($opt)
        {
            case "Members":
            $query = "SELECT * FROM members where memberName LIKE '%$searchval%'";
            $res = mysqli_query($conn, $query) or die(mysqli_error());
            $count = mysqli_num_rows($res);
            if($count > 1)
            {
                $output .= "$count results for <strong>$escsearch</strong>.";
                while($row = mysqli_fetch_array($res))
                {
                    $name = $row['memberName'];
                    $pos = $row['position'];
                    $fac = $row['faculty'];
                    $email = $row['email'];
                    $int = $row['research_interests'];
                    echo "<table>
                            <tr>
                                <td>Name</td>
                                <td>Position</td>
                                <td>Faculty</td>
                                <td>E-mail</td>
                                <td>Research Interests</td>
                            </tr>
                            <tr>
                                <td>$name</td>
                                <td>$pos</td>
                                <td>$fac</td>
                                <td>$email</td>
                                <td>$int</td>
                            </tr>
                         </table>";
                }
            }else{
                $output = "<p>No records found.</p>"; 
            }
            break;
        }
    }
}
 
     
     
    