title: SWITCH / CASE Multiple Submit Buttons with PHP using POST method
body: <p>First, I'm a noob in PHP and using Forms, but I'm learning as I go!
  Second, I know this has been covered many times, but I just can't make it work for me! It's probably just something I'm overlooking...</p>
  
  <p>I have a form with 1 search field and 3 submit buttons.
  Depending on the button selected, the query will look in the database for one of 3 different searches. It's fairly simple...</p>
  
  <p><a href="http://1karaokedj.com" rel="nofollow">http://1karaokedj.com</a></p>
  
  <pre><code>&lt;input name="searchterm" type="search" placeholder="Enter Search Terms Here"  class="search" /&gt;
  &lt;input name="searchbtn" type="submit" id="searchbtn" class="searchbutton" value="Artist Search"  /&gt;
  &lt;input name="searchbtn" type="submit" id="searchbtn" class="searchbutton" value="Title Search"  /&gt;
  &lt;input name="searchbtn" type="submit" id="searchbtn" class="searchbutton" value="Disc ID Search"  /&gt;
  &lt;?php if(isset($_SESSION['searchterm'])) {
            if(($_SESSION['searchterm']!="")) {
              switch ($_POST['searchbtn']) {
                case 'Artist Search':
                  $searchresults=$db-&gt;query("select * from 1KaraokeDJ where Artist like '%$searchterm%' limit 100");
                  break;
                case 'Title Search':
                  $searchresults=$db-&gt;query("select * from 1KaraokeDJ where Title like '%$searchterm%' limit 100");
                  break;
                case 'Disc ID Search':
                  $searchresults=$db-&gt;query("select * from 1KaraokeDJ where Disc like '%$searchterm%' limit 100");
                  break;
              }
  
              if(mysqli_num_rows($searchresults) &gt; 0) {
  ...
  }}}?&gt;
  </code></pre>
  
  <p>this always returns no records found.
  if I add a default case then it works
  print_r($_POST); returns "Array()"</p>
  
  <p>here is the full code in case the problem is elsewhere:</p>
  
  <pre><code>&lt;?php
    include("connect.php");
    require_once 'Mobile_Detect.php';
    $detect = new Mobile_Detect;
    ini_set('session.cookie_lifetime',900);
    ini_set('session.gc_maxlifetime',900);
    session_start();
    if(isset($_POST['searchbtn'])) {
      $_SESSION['searchterm']=$_POST['searchterm'];
      if(($_SESSION['searchterm'])!="") { header("location:index.php"); }
      else { echo "&lt;script&gt; alert('Please enter something to search for') &lt;/script&gt;"; }
    }
  ?&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;1KaraokeDJ.com Search&lt;/title&gt;
      &lt;link rel="stylesheet" href="style.css" /&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div class="container"&gt;
        &lt;form method="post"&gt;
          &lt;p&gt;&lt;code&gt;
            &lt;img src="top1.jpg" /&gt;&lt;br&gt;
            &lt;?php if ($detect-&gt;isMobile()) { echo("Mobile Device Detected"); } else { echo("Desktop Browser Detected"); } ?&gt;
          &lt;/code&gt;&lt;/p&gt;
          &lt;p&gt;
            &lt;?php if(isset($_SESSION['searchterm'])) { ?&gt;
              &lt;input name="searchterm" type="search" value="&lt;?php echo $_SESSION['searchterm'];?&gt;" class="search" /&gt;
            &lt;?php } else { ?&gt;
              &lt;input name="searchterm" type="search" placeholder="Enter Search Terms Here"  class="search" /&gt;
            &lt;?php } ?&gt;
          &lt;/p&gt;
          &lt;p&gt;
            &lt;input name="searchbtn" type="submit" id="searchbtn" class="searchbutton" value="Artist Search"  /&gt;
            &lt;input name="searchbtn" type="submit" id="searchbtn" class="searchbutton" value="Title Search"  /&gt;
            &lt;input name="searchbtn" type="submit" id="searchbtn" class="searchbutton" value="Disc ID Search"  /&gt;
          &lt;/p&gt;
          &lt;hr style="width:100%"&gt;
          &lt;?php if(isset($_SESSION['searchterm'])) {
            if(($_SESSION['searchterm']!="")) {
              $searchterm=strtoupper($_SESSION['searchterm']);
  
              print_r($_POST);
  
              switch ($_POST['searchbtn']) {
                case 'Artist Search':
                  $searchresults=$db-&gt;query("select * from 1KaraokeDJ where Artist like '%$searchterm%' limit 100");
                  break;
                case 'Title Search':
                  $searchresults=$db-&gt;query("select * from 1KaraokeDJ where Title like '%$searchterm%' limit 100");
                  break;
                case 'Disc ID Search':
                  $searchresults=$db-&gt;query("select * from 1KaraokeDJ where Disc like '%$searchterm%' limit 100");
                  break;
              }
  
              if(mysqli_num_rows($searchresults) &gt; 0) {
                while($descri=mysqli_fetch_object($searchresults)) { ?&gt;
          &lt;div class="reslt"&gt;
            &lt;h3 id="results"&gt;
              &lt;?php
                echo str_ireplace($searchterm, '&lt;span class="highlight"&gt;'.$searchterm."&lt;/span&gt;", $descri-&gt;Artist);
                echo " - ";
                echo str_ireplace($searchterm, '&lt;span class="highlight"&gt;'.$searchterm."&lt;/span&gt;", $descri-&gt;Title);
              ?&gt;
            &lt;/h3&gt;
            &lt;p class="Description"&gt;
              &lt;?php
                echo str_ireplace($searchterm, '&lt;span class="highlight"&gt;'.$searchterm."&lt;/span&gt;", $descri-&gt;Brand);
                echo " - ";
                echo str_ireplace($searchterm, '&lt;span class="highlight"&gt;'.$searchterm."&lt;/span&gt;", $descri-&gt;Disc);
                echo " - ";
                echo $descri-&gt;Track;
              ?&gt;
            &lt;p&gt;
            &lt;hr&gt;
          &lt;/div&gt;
          &lt;?php } ?&gt;
          &lt;div class="reslt"&gt;
            &lt;h3 id="results"&gt;&lt;?php echo mysqli_num_rows($searchresults) ?&gt; Results&lt;/h3&gt;
            &lt;?php if(mysqli_num_rows($searchresults) &gt;= 100) { ?&gt;
              &lt;p class="Description highlight"&gt;Showing Up To 100 Results&lt;br&gt;Try Refining Your Search&lt;/p&gt;&lt;hr&gt; 
            &lt;?php } ?&gt;
          &lt;/div&gt;
          &lt;?php   } else { ?&gt;
          &lt;div class="reslt"&gt;
            &lt;h3 id="results"&gt;Nothing Found!&lt;/h3&gt;
            &lt;p class="Description highlight"&gt;Try Changing Your Search Terms&lt;p&gt;&lt;hr&gt;
          &lt;/div&gt;
          &lt;?php } } } ?&gt;
        &lt;/form&gt;
        &lt;code&gt;This site is in testing... Things may change anytime&lt;br&gt;and many things may not work for a while!&lt;/code&gt;
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>