title: Undefined index when submitting HTML form via POST method
body: <p>I have been searching days why this piece of code is not working. Adjusted the code multiple times by searching for posts with the same problem. </p>
  
  <p>Problem: my php file doesn't seem to get the values it needs from a simple HTML form (made w. bootstrap) via POST-method. I use the issit function to check if the submit button has been clicked and thereafter I use to check if the form was filled out completely.</p>
  
  <p>Please note that I am relatively new to php. I hope I did miss something and it is not just a simple typo.</p>
  
  <p>PHP code (bootstrap/php/boeking.php)</p>
  
  <pre><code>&lt;?php
  
  //&lt;!--debug--&gt;
  
  error_reporting(E_ALL);
  ini_set('display_errors', '1');
  
  
  //&lt;!--connectie--&gt;
  
  mysql_connect("localhost","root","root") or die(mysql_error());
  mysql_select_db("hota") or die(mysql_error());
  
  
  //&lt;!--boeking info verzenden--&gt;
  
  if(isset($_POST['send']))
  
  {
  
  if (isset($_POST['achternaam'])) 
  {
     $anaam = $_POST['achternaam'];
     // do whatever here
  }
  
  if(isset($_POST['voornaam']))
  {
  $vnaam =  $_POST['voornaam'];
  
  }
  
  }
  
  
  
  $anaam = mysql_real_escape_string($anaam);
  $vnaam = mysql_real_escape_string($vnaam);
  
  
  $boek = "INSERT INTO klant (achternaam , voornaam) VALUES ('{$anaam}', '{$vnaam}')";
  
  mysql_query($boek);
  
  ?&gt;
  </code></pre>
  
  <p>HTML code:</p>
  
  <pre><code>&lt;form id="newbook" method="POST" action="bootstrap/php/boeking.php" class="form-horizontal"&gt;
    &lt;legend&gt;Nieuwe boeking&lt;/legend&gt;
     &lt;div class="control-group"&gt;
        &lt;label class="control-label" for="voornaam"&gt;Voornaam&lt;/label&gt;
        &lt;div class="controls"&gt;
          &lt;input type="text" name="voornaam" id="voornaam" placeholder="Voornaam"&gt;
        &lt;/div&gt;
     &lt;/div&gt;
     &lt;div class="control-group"&gt;
        &lt;label class="control-label" for="achternaam"&gt;Achternaam&lt;/label&gt;
        &lt;div class="controls"&gt;
          &lt;input type="text" name="achternaam" id="achternaam" placeholder="Achternaam"&gt;
        &lt;/div&gt;
      &lt;/div&gt;
     &lt;div class="control-group"&gt;
        &lt;div class="controls"&gt;
          &lt;button type="submit" name="send" class="btn"&gt;Sign in&lt;/button&gt;
        &lt;/div&gt;
     &lt;/div&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p>Thanks in advance!</p>
  
  <p><strong>UPDATE:</strong> </p>
  
  <p>changed my php-code.</p>
  
  <p>Not getting the undefined index error anymore.<br>
  Var_dump($vnaam); and var_dump($anaam); do indicate that strings are passed to the php but after that, when the query is fired, things don't seem to get send to the db.</p>
  
  <p>Might this be a problem in my query ?</p>
  
  <p>(already thanks for the tips: gave the button a value and used var_dump)</p>
  
  <p>This is my new code : </p>
  
  <pre><code>&lt;?php
  
  //&lt;!--debug--&gt;
  
  error_reporting(E_ALL);
  ini_set('display_errors', '1');
  
  
  //&lt;!--connectie--&gt;
  
  mysql_connect("localhost","root","root") or die(mysql_error());
  mysql_select_db("hota") or die(mysql_error());
  
  
  $anaam = '';
  $vnaam = '';
  
  
  if(!isset($_POST['send'])) { 
  
  } 
   else
  {
  
  if (isset($_POST['achternaam'])) 
  {
     $anaam = $_POST['achternaam'];
     // do whatever here
  
  }
  
  if(isset($_POST['voornaam']))
  {
  $vnaam =  $_POST['voornaam'];
  
  
  }
  var_dump($vnaam);
  var_dump($anaam);
  
  
      $anaam = mysql_real_escape_string($anaam);
      $vnaam = mysql_real_escape_string($vnaam);
  
  }
  
  var_dump($vnaam);
  
  
  $boek = "INSERT INTO klant (achternaam , voornaam) VALUES ('{$anaam}', '{$vnaam}')";
  
  mysql_query($boek);
  
  ?&gt;
  </code></pre>