title: Php form validation using prepared statements not working
body: <p>It's my first time validating a php form with prepared statements and i'm coming across some problems.</p>
  
  <p>I'm using Form.php for the validation and insertion onto the database which is being called in the index.php form.</p>
  
  <p>The problem is that the errors messages don't show up. I can press the button 'Submit' and the form is processed even without inserting data in the input boxes!</p>
  
  <p>I've been stubborn, trying to do things on my own but since i've been stuck with this form for days and before i throw in the towel i feel i should ask for help at this point.</p>
  
  <p>Here is the form code in Index.php:</p>
  
  <pre><code>&lt;form id="form" name="contactForm" method="post" action="php/Form.php"&gt;
              &lt;div&gt;
                  &lt;label for="name"&gt;Your name&lt;/label&gt; 
                  &lt;input type="text" id="name" name="name" maxlength="40" placeholder="Write your Name"   &gt;
                  &lt;span class="error"&gt;&lt;?php echo $nameError;  ?&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div&gt;
                  &lt;label for="email"&gt;Your email&lt;/label&gt;
                  &lt;input type="email" id="email" name="user_mail" placeholder="email@example.com"&gt;
                  &lt;span class="error"&gt;&lt;?php echo $emailError;  ?&gt;&lt;/span&gt; 
              &lt;/div&gt;                
              &lt;div&gt;
                  &lt;label for="topic"&gt;Select Topic&lt;/label&gt;
                  &lt;select id="topic" name="topic"&gt;
                      &lt;option selected disabled hidden value=""&gt;Choose a Topic&lt;/option&gt;
                      &lt;option value="link"&gt;Site Link&lt;/option&gt;
                      &lt;option value="copyright"&gt;Copyright&lt;/option&gt;
                      &lt;option value="errors"&gt;Site/Article errors&lt;/option&gt;
                      &lt;option value="feedback"&gt;Feedback&lt;/option&gt;
                      &lt;option value="other"&gt;Other&lt;/option&gt;
                  &lt;/select&gt;
                  &lt;span class="error"&gt;&lt;?php echo $topicError;  ?&gt;&lt;/span&gt;
              &lt;/div&gt;                
              &lt;div&gt;
                  &lt;label for="msg"&gt;Your message&lt;/label&gt;
                  &lt;textarea id="msg" name="user_message" placeholder="Write your message"&gt;&lt;/textarea&gt;
                  &lt;span class="error"&gt;&lt;?php echo $msgError;  ?&gt;&lt;/span&gt;
              &lt;/div&gt;                
              &lt;div class="button"&gt;
                  &lt;button type="submit" id="submit" name="submit"  value="true"&gt;Submit&lt;/button&gt; 
                  &lt;span class="success"&gt;&lt;/span&gt;
              &lt;/div&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>And here is the Form.php</p>
  
  <pre><code>&lt;?php
  
  $servername = "localhost:3306";
  $username = "root";
  $password = "";
  $dbname = "site_comboios";
  
  
  $nameError = "";
  $emailError = "";
  $topicError = "";
  $msgError = "";
  
  $name = $_POST['name'];
  $email = $_POST['user_mail'];
  $topic = $_POST['topic'];
  $msg = $_POST['user_message'];
  
  if( isset( $_POST['submit'])) {
  if(empty( $name) &amp;&amp; !isset($name) ) {
      $nameError = "Name is required";
  }
  
  if(empty( $email) &amp;&amp; !isset($email)) {
      $emailError = "Email is required";
  } elseif(filter_var($email,FILTER_VALIDATE_EMAIL)) {
    $emailError = "Please insert a correct email address";  
  }  
  
  if(empty( $topic) &amp;&amp; !isset($topic) ) {
      $topicError = "Please choose a topic";
  } 
  
  if(empty( $msg) &amp;&amp; !isset($msg) ) {
      $msgError = "Let us know your opinion";
  }
  }
  
  //Create connection to database
  $mysqli = new mysqli($servername, $username, $password, $dbname);
  
  //check connection
  if($mysqli-&gt;connect_errno) {
  echo 'Error connecting to database';
  }
  
  //Prepared Statement
  $stmt = $mysqli-&gt;prepare("INSERT INTO contacts(Nome, Email, Topico,    Mensagem)  VALUES(?, ?, ?, ?)" );
  $stmt-&gt;bind_param('ssss', $name, $email, $topic, $msg);
  $stmt-&gt;execute();
  </code></pre>