title: MySQL insert into apparently not executing using an HTML form, PHP, and MySQL
body: <p>I am a beginner "programmer" so please excuse my ignorance.  I am using a prepared statement in the interest of security.  The else clause is echoed instead of the INSERT INTO statement executing.  I am passing a hidden value from the HTML form:</p>
  
  <pre><code>&lt;input type="hidden" value="EVS1" name="CustomerCode" /&gt;
  &lt;?php   
  
  include ('../etc/mysql_connect.php');
  
  
  if(isset($_POST['submit'])) {
  
  $FirstName= trim( $_POST['FirstName'] );
  $LastName= trim( $_POST['LastName'] );
  $Address1= trim( $_POST['Address1'] );
  $Address2= trim( $_POST['Address2'] );
  $City= trim( $_POST['City'] );
  $State= trim( $_POST['State'] );
  $Zip= trim( $_POST['Zip'] );
  $Email= trim( $_POST['Email'] );
  
  
  
  $calculated_date = date('m-d-Y', time() + 86400 * 42);
  
  
  
  $stmt = $conn-&gt;prepare("INSERT INTO xxx SET FirstName = ?,LastName = ?,Address1 = ?,Address2         = ?,City = ?,State = ?,Zip = ?,Email = ?,CustomerCode = CustomerCode,DrawingEntryDate = NOW() ");
  
  $stmt-&gt;bind_param("sssssssss", $_POST['FirstName'] , $_POST['LastName'], $_POST['Address1'],           $_POST['Address2'], $_POST['City'], $_POST['State'], $_POST['Zip'], $_POST['Email'], $_POST['CustomerCode']);
  
  $stmt-&gt;execute();
  
  $affected_rows= mysqli_stmt_affected_rows ($stmt);
  
    if ($affected_rows ==1){
      echo '&lt;body bgcolor="#F9F9F9"&gt;&lt;h2&gt;Thank You!&lt;/h2&gt;&lt;font type="Arial,Helvetica, sans-serif"              size="3"&gt;We have successfully received your entry.  Good luck!&lt;br&gt;&lt;br&gt;Names are drawn randomly each month, and notified via email.  If your name is chosen, please expect delivery within 4-6 weeks.  Your order is scheduled to be delivered by '.$calculated_date.'.&lt;/font&gt;&lt;/body&gt;';
  
        mysqli_stmt_close($stmt);
        mysqli_close($dbconnect);
  
     }  else {
        echo '&lt;body bgcolor="#F9F9F9"&gt;&lt;h2&gt;Oops!&lt;/h2&gt;&lt;font type="Arial,Helvetica, sans-serif" size="3"&gt;There is a limit of 1 entry per day.  &lt;b&gt;'.$FirstName.'&lt;/b&gt; has already entered on '.$DrawingEntryDate.' .&lt;/font&gt;&lt;/body&gt;';
        echo mysqli_error();
  
        mysqli_stmt_close($stmt);
        mysqli_close($dbconnect);
     }
  }
  ?&gt;
  </code></pre>