Data wont insert into Database
<p>I'm trying to insert data from a form to my database but it doesn't seem to work. I've put an echo after the insert query so I can verify that the data was inserted but it doesn't echo what I've written. Is there a problem with my query or any part of my php?</p>

<p>My PHP:</p>

<pre><code>&lt;?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "stat_system";

$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$fname = $lname = $mname = $contact = $age = $attain = $course = $school = $position = $exp = $ref = $batchtxt = $hiredate = $prevbpo = $remarks = $nho = $nonbpo = $holdAttain = $holdPos = "";
$error_flag = 0;                   


if (isset($_POST['submit'])) {

                $holdAttain = (isset($_POST['cmbAttain']));
                $holdPos = (isset($_POST['cmbPosition']));

                if (!empty($_POST['firstname'])) {
                    $fname = $_POST['firstname'];
                }

                if (!empty($_POST['lastname'])) {
                    $lname = $_POST['lastname'];
                }

                if (!empty($_POST['middlename'])) {
                    $mname = $_POST['middlename'];
                }

                if (!empty($_POST['contact'])) {
                    $contact = $_POST['contact'];
                }

                if (!empty($_POST['age'])) {
                    $age = $_POST['age'];
                }

                if (isset($_POST['cmbAttain'])) {
                    $attain = $_POST['cmbAttain'];
                }

                if(isset($_POST['school'])) {
                    $school = $_POST['school'];
                }

                if(isset($_POST['course'])) {
                    $course = $_POST['course'];
                }

                if (isset($_POST['exp'])) {
                    $exp = $_POST['exp'];
                }

                if (!empty($_POST['remarks'])) {
                    $remarks = $_POST['remarks'];
                }

                if (isset($_POST['nonbpo'])) {
                    $nonbpo = $_POST['nonbpo'];
                }

                if (isset($_POST['prevbpo'])) {
                    $prevbpo = $_POST['prevbpo'];
                }

                if (!empty($_POST['ref'])) {
                    $ref = $_POST['ref'];
                }

                if (isset($_POST['hiredate'])) {
                    $hiredate = $_POST['hiredate'];
                }

                if (isset($_POST['batchtxt'])) {
                    $batchtxt = $_POST['batchtxt'];
                }

                if (!empty($_POST['nho'])) {
                    $nho = $_POST['nho'];
                }

                if($error_flag == 0){
                    $sql = mysqli_query($conn,"INSERT INTO applicants (appID, appLastName, appFirstName, appMidleName, Age, appPhoneNumber, appBatch, appExperience, appRemarks, appPreviousBPO, appSchool, appCourse, appGraduate, appNonBPO, appPosition, appHireDate, appNHO, appReferrer)
                                                     VALUES (NULL, '$lname', '$fname', '$mname', $age, '$contact', $batchtxt, '$exp', $remarks, '$school', '$course', '$attain', '$nonbpo', '$position', $hiredate, $nho, '$ref')");
                       echo "&lt;script type='text/javascript'&gt;
                        $(document).ready(function(){
                        $('#succModal').modal('show');
                        });
                        &lt;/script&gt;";
                    $fname = $lname = $mname = $contact = $age = $attain = $course = $school = $batchtxt = $ref = $hiredate = $position = $exp = $prevbpo = $remarks = $nho = $nonbpo = $holdAttain = $holdPos = "";

                }
                else {
                    print '&lt;script type="text/javascript"&gt;'; 
                    print 'alert("Please fill in all the fields!")';
                    print '&lt;/script&gt;';

                }
            }

    mysqli_close($conn);
?&gt;
</code></pre>

<p>My HTML:</p>

<pre><code> &lt;div id="addApplicant" class="addApp-marginleft" style="height:1000px"&gt;

        &lt;form id="registration" class="form-horizontal" method="post" action="index.php"&gt;
            &lt;div class="row"&gt;
                &lt;div  align="center"&gt;
                    &lt;h3&gt;Add Applicant&lt;/h3&gt;
                    &lt;br&gt;
                &lt;/div&gt;
            &lt;/div&gt;

            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;First name:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                    &lt;input required type="text" name="firstname" autocomplete="off" placeholder="Firstname" id="firstname" class="form-control" value="&lt;?php echo $fname;?&gt;"&gt;
                &lt;/div&gt;
                &lt;div class="col-sm-4"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt; Last name:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                    &lt;input required type="text" name="lastname" autocomplete="off" id="lastname" placeholder="Lastname" class="form-control" value="&lt;?php echo $lname;?&gt;"&gt;
                &lt;/div&gt;
                &lt;div class="col-sm-4"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;Middle name:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                    &lt;input required type="text" name="middlename" autocomplete="off" id="middlename" placeholder="middlename" class="form-control" value="&lt;?php echo $mname;?&gt;"&gt;
                &lt;/div&gt;
                &lt;div class="col-sm-4"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;Contact number:&lt;/small&gt;&lt;/label&gt;
                &lt;span id="errmsg"&gt;&lt;/span&gt;
                &lt;div class="col-sm-4"&gt;
                    &lt;input required type="text" name="contactnum" autocomplete="off" onkeypress="return isNumber(event)" placeholder="Contact number" id="contact" class="form-control" maxlength="11" value="&lt;?php echo $contact;?&gt;"/&gt;
                &lt;/div&gt;
                &lt;?php
                    echo '&lt;script&gt;';
                    echo 'function isNumber(evt) {';
                        echo 'evt = (evt) ? evt : window.event;';
                        echo 'var charCode = (evt.which) ? evt.which : evt.keyCode;';
                        echo 'if (charCode &gt; 31 &amp;&amp; (charCode &lt; 48 || charCode &gt; 57)) {';
                            echo 'return false;';
                        echo '}';
                        echo 'return true;';
                    echo '}';
                    echo '&lt;/script&gt;';
                ?&gt;
                &lt;div class="col-sm-4"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;Age:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                    &lt;input required type="text" autocomplete="off" placeholder="age" name="age" id="age" class="form-control" value="&lt;?php echo $age;?&gt;"&gt;
                &lt;/div&gt;
                &lt;div class="col-sm-4"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;Graduate:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                    &lt;select required name="cmbAttain" id="cmbAttain" class="form-control" onChange="disableCmb();"&gt;
                        &lt;option value=""&gt;Choose&lt;/option&gt;
                        &lt;option value="Yes" &lt;?php if($holdAttain == "Yes") echo "selected"; ?&gt;&gt;Yes&lt;/option&gt;
                        &lt;option value="No" &lt;?php if($holdAttain == "No") echo "selected"; ?&gt;&gt;No&lt;/option&gt;
                    &lt;/select&gt;

                &lt;/div&gt;
                &lt;div class="col-sm-4"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;School:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                   &lt;input type="text" name="school" autocomplete="off" id="school" placeholder="School" class="form-control" value="&lt;?php echo $school;?&gt;"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;Course:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                   &lt;input type="text" name="course" autocomplete="off" id="course" placeholder="Course" class="form-control" value="&lt;?php echo $course;?&gt;"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;Batch:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                   &lt;input type="text" name="batchtxt" autocomplete="off" id="batchtxt" placeholder="Batch" class="form-control" value="&lt;?php echo $batchtxt;?&gt;"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;Experience:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                   &lt;input type="text" name="exp" autocomplete="off" id="exp" placeholder="Experience" class="form-control" value="&lt;?php echo $exp;?&gt;"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;Previous BPO:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                   &lt;input type="text" name="prevbpo" autocomplete="off" id="prevbpo" placeholder="Previous BPO" class="form-control" value="&lt;?php echo $prevbpo;?&gt;"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;Non-BPO:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                   &lt;input type="text" name="nonbpo" autocomplete="off" id="nonbpo" placeholder="Non-BPO" class="form-control" value="&lt;?php echo $nonbpo;?&gt;"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;Remarks:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                   &lt;input type="text" name="remarks" autocomplete="off" id="remarks" placeholder="Remarks" class="form-control" value="&lt;?php echo $remarks;?&gt;"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;Hire Date:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                    &lt;input type="date" name="hiredate" id="hiredate" class="form-control" autocomplete="off" value="&lt;?php echo $hiredate;?&gt;"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;Position:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                    &lt;select required name="cmbPosition" id="cmbPosition" class="form-control" data-size="5" &gt;
                        &lt;option selected value=""&gt;Choose&lt;/option&gt;
                        &lt;option value="Customer Service Representative" &lt;?php if($holdPos == "Customer Service Representative") echo "selected"; ?&gt;&gt;Customer Service Representative&lt;/option&gt;
                        &lt;option value="Image Enhancer" &lt;?php if($holdPos == "Image Enhancer") echo "selected"; ?&gt;&gt;Image Enhancer&lt;/option&gt;
                    &lt;/select&gt;
                &lt;/div&gt;
                &lt;div class="col-sm-4"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;NHO:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                    &lt;input type="date" name="nho" id="nho" class="form-control" autocomplete="off" value="&lt;?php echo $nho;?&gt;"&gt;
                    &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;label class="col-sm-4 control-label"&gt;&lt;small&gt;Referrer:&lt;/small&gt;&lt;/label&gt;
                &lt;div class="col-sm-4"&gt;
                   &lt;input type="text" name="ref" autocomplete="off" id="ref" placeholder="Name of Referrer" class="form-control" value="&lt;?php echo $ref;?&gt;"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" align="center" &gt;
                &lt;div class="col-sm-4"&gt;
                &lt;/div&gt;
                &lt;div class="col-sm-4"&gt;
                    &lt;div class="btn-group " role="group" aria-label="..."&gt;
                        &lt;input id="submitbtn" type="submit" name="submit" class="btn btn btn-success" value="Submit" data-target="#succModal"&gt;
                        &lt;input type="reset" name="reset" class="btn btn-warning" value="Clear"&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class="col-sm-4"&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/form&gt;
    &lt;/div&gt; 
  &lt;div class="container"&gt;
     &lt;!-- Register Success Modal --&gt;
        &lt;div class="modal fade" id="succModal" role="dialog"&gt;
            &lt;div class="modal-dialog modal-sm"&gt;
                &lt;div class="modal-content"&gt;

                    &lt;div class="modal-body" align="center"&gt;

                      &lt;p&gt;REGISTRATION SUCCESSFUL&lt;/p&gt;
                      &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
</code></pre>