未插入MySQL表的表单数据[关闭]

I have tried everything I can think of but the data from my form do not get inserted in the MySQL table. This is relevant part of my form:

<form id="masteringhtml5_form" action="send_formdata.php" method="POST">
    <label for="heading" class="heading">Health Survey Form</label>
    <fieldset class="fieldset_border">
         <legend class="legend">Personal Information</legend>
        <div>
            <label for="name">Name</label><br>
            <input type="text" name="Firstname" class="name txtinput" placeholder="First" autofocus>
            <input type="text" name="Lastname" class="name txtinput" placeholder="Last">
       </div>
       <!-- other input fields here -->
       <div class="submit">
           <input type="submit" name="submit" class="submit_btn" value="Submit">
       </div>
</form>

And this is relevant part of my php file "send_formdata.php":

<?php
mysqli_connect("localhost:3308","root","9gUCFpWmzh");
mysqli_select_db("personal_info");

if(isset($_REQUEST['submit'])) {
    $errorMessage = "";
    $Firstname=$_POST['Firstname'];
    $Lastname=$_POST['Lastname'];
    // other variables and validation here
    if ($errorMessage != "" ) {
        echo "<p class='message'>" .$errorMessage. "</p>" ;
    } else {
        //Inserting record in table using INSERT query
        $insertTB="INSERT INTO `personal_info`.`personal`
        (`Firstname`, `Lastname`, `Dob`, `Gender`, `Saddress`,
        `Aaddress`, `City`, `State`, `Pincode`, `Country`, `Home`,
        `Work`, `Email`) VALUES ('$Firstname', '$Lastname', '$Dob',
        '$Gender', '$Saddress', '$Aaddress', '$City', '$State',
        '$Pincode', '$Country', '$Home', '$Work', '$Email')";
        mysqli_query($insertTB);
    }
}
?>

The database and table are correct. I have run the script with "echo $insertTB" and that produces a full query statement in the browser.

Change your PHP Code to

$link = mysqli_connect("localhost:3308","root","9gUCFpWmzh")  or die("cannot connect to server !!");
//mysqli_select_db("personal_info");
mysqli_select_db($link,"personal_info");
if(isset($_REQUEST['submit']))
{
    $errorMessage = "";
    $Firstname=$_POST['Firstname'];
    $Lastname=$_POST['Lastname'];
    // other variables and validation here
    if ($errorMessage != "" ) {
        echo "<p class='message'>" .$errorMessage. "</p>" ;
    }
    else{
        //Inserting record in table using INSERT query
        $insertTB="INSERT INTO `personal_info`.`personal`
        (`Firstname`, `Lastname`, `Dob`, `Gender`, `Saddress`,
        `Aaddress`, `City`, `State`, `Pincode`, `Country`, `Home`,
        `Work`, `Email`) VALUES ('$Firstname', '$Lastname', '$Dob',
        '$Gender', '$Saddress', '$Aaddress', '$City', '$State',
        '$Pincode', '$Country', '$Home', '$Work', '$Email')";
        //mysqli_query($insertTB);
        mysqli_query($link,$insertTB) or die(mysqli_error($link));
    }
}

You should change Insert query as following,

Replace

$insertTB="INSERT INTO `personal_info`.`personal`
        (`Firstname`, `Lastname`, `Dob`, `Gender`, `Saddress`,
        `Aaddress`, `City`, `State`, `Pincode`, `Country`, `Home`,
        `Work`, `Email`) VALUES ('$Firstname', '$Lastname', '$Dob',
        '$Gender', '$Saddress', '$Aaddress', '$City', '$State',
        '$Pincode', '$Country', '$Home', '$Work', '$Email')";
        mysqli_query($insertTB);

With

$insertTB="INSERT INTO `personal_info`.`personal`
        (`Firstname`, `Lastname`, `Dob`, `Gender`, `Saddress`,
        `Aaddress`, `City`, `State`, `Pincode`, `Country`, `Home`,
        `Work`, `Email`) VALUES ('".$Firstname."', '".$Lastname."', '".$Dob."',
        '".$Gender."', '".$Saddress."', '".$Aaddress."', '".$City."', '".$State.",
        '".$Pincode."', '".$Country."', '".$Home."', '".$Work."', '".$Email."')";
        mysqli_query($insertTB);

we have to always write variable with '".$address."' in insert query as standard practice, because if we cant write like this, sometime it will break query when pass value in any field like "john's street",. so single quote (') break the query, values do not insert into table,

To debug general php errors, add on top of your script this:

error_reporting(E_ALL);
ini_set('display_errors', '1');

To debug your db connection:

$dbCon = mysqli_connect('localhost', 'root', '9gUCFpWmzh', 'personal_info');
if (!$dbCon) { echo 'Connect Error ('.mysqli_connect_errno().')'. mysqli_connect_error(); exit(); }

To debug query errors, change your mysqli_query() to:

mysqli_query($dbCon, $insertTB) or die(mysqli_error($dbCon));

For each field you insert into your database, modify your query.
Instead of '$Firstname'
Change to '".mysqli_real_escape_string($dbCon, $Firstname)."'
Do this for all your fields.