title: PHP Multiple forms on same page with multiple buttons
body: <p>I'm busy coding a website for a local business that does Milkshakes. Naturally, they wanted to show their flavours on the site and have a management page where they could edit them. I have gotten the flavours to show up on the main page, but I am having a problem with the management page.</p>
  
  <p>I have a database set up that contains a list of the flavours. The 3 main things that I am trying to allow them to do is edit, delete and add new entries. Currently, I am calling out each row (or each flavour and its id) as separate forms with 2 submit buttons: one to save changes, and one to remove it. 
  Code is below:</p>
  
  <p>for the management page:</p>
  
  <pre><code>&lt;?php
  $con = new PDO('mysql:host=host;dbname=dbname', "user", "password");
  $con -&gt; setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $query = "SELECT * FROM FlavourShakes";
  $data = $con-&gt;query($query);
  $rows = $data-&gt;fetchAll(PDO::FETCH_ASSOC);
  
  foreach ($rows as $row) {
      $id = $row['id'];
      $flavour = $row['Flavour'];
      print "&lt;form action=\"saveFlavorShakes.php\" method=\"post\"&gt; \n
              &lt;fieldset&gt; \n 
                  &lt;input name=\"id\" value=\"$id\" readonly/&gt; \n 
                  &lt;input name=\"Flavour\" value=\"$flavour\" /&gt; \n
                  &lt;input type=\"submit\" name=\"edit\" value=\"Save\"&gt; \n 
                  &lt;input type=\"submit\" name=\"edit\" value=\"Remove\"&gt; \n 
              &lt;/fieldset&gt; \n 
             &lt;/form&gt; \n";
  }
  ?&gt;  
  
  &lt;form action="saveFlavorShakes.php" method="post"&gt;
      &lt;fieldset&gt;
          &lt;input name="Flavour" /&gt;
          &lt;input type="submit" name="edit" value="Add"&gt;
      &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and on my processing page:</p>
  
  <pre><code>&lt;?php
  $flavour = $_POST['Flavour'];
  $id = $_POST['id'];
  $btnType = $_POST['edit'];
  
  $con = new PDO('mysql:host=hostname;dbname=dbname', "user", "password");
  $con -&gt; setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $query = "";
  
  try
  {
      switch($_POST['edit']){
          case'Save':                             
              $query =    "UPDATE FlavorShakes
                          SET Flavour= :name,
                          WHERE id = :id;";
              $notice = "saveOK";
              $_POST['notice'] = $notice;
              break;
          case'Add':
              $query = "INSERT INTO FlavourShakes(Flavour) VALUES (:name);";
              $notice = "addOK";
              $_POST['notice'] = $notice;
              break;
          }
          //I know I haven't added a case for the remove button yet.
  
  
          $statement = $con-&gt;prepare($query);
          $statement-&gt;bindValue(":id", $id);
          $statement-&gt;bindValue(":name", $flavour);
  
          $count = $statement-&gt;execute(); 
  
      header('Location: EditFlavorShakes.php');   
  }
  
  catch(PDOException $e) {
      if ($btnType = "save"){ 
          $notice = "saveBad";
          $error = $e-&gt;getMessage();  
          $_POST['notice'] = $notice;
          $_POST['error'] = $error;
      } elseif($btnType = "delete"){ 
          $notice = "delBad";
          $error = $e-&gt;getMessage();
          $_POST['notice'] = $notice;
          $_POST['error'] = $error;           
      }elseif($btnType = "add"){ 
          $notice = "addBad";
          $error = $e-&gt;getMessage();  
          $_POST['notice'] = $notice;
          $_POST['error'] = $error;   
      }else{
          $notice = "otherBad";
          $error = $e-&gt;getMessage();
          $_POST['notice'] = $notice;
          $_POST['error'] = $error;   
      }
      echo $notice;
      echo $e-&gt;getMessage();
  
      //header('Location: EditFlavorShakes.php');
  }
  ?&gt;
  </code></pre>
  
  <p>Currently, I don't have any entries in the database. However, when I try to add Chocolate and click the Add button, I get this error:</p>
  
  <blockquote>
    <p>saveBadSQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens</p>
  </blockquote>
  
  <p>What I don't understand is why it <code>$_POST['edit']</code> set to save instead of add? I feel like I am overlooking some stupidly simple mistake in my code. If anyone can help me I would appreciate it. </p>
  
  <p>Thanks in advance.</p>