将用户的表单数据插入数据库

时间:2018-11-28 20:38:41

标签: php mysql database insert

我当前正在尝试从用户文本表单中获取信息,并将其发送到我的数据库。我正在与Xampp合作。 这是我的表单的摘要,用于获取用户数据。

<div id="section-clientinformation" class="tab-content">
<div class="tab-pane fade in active">
<h2>Client Information</h2>
<p>Please enter your information. All information will be stored into our database.</p>
<form action = "/db_connection_clientinfo.php" method=post">
First name: <input class= "from control item" type="text" name="FirstName"   maxlength="15" minlength="3" id="firstname" placeholder="name" required><br>
Last name: <input class= "from control item" type="text" name="LastName"maxlength="15" minlength="3" id="lastname" placeholder="lastname"  required><br>
Address: <input type="text" name="Address" minlength="7" id="address" placeholder="use complete address" required>
<br>
City: <input type="text" name="City" minlength="2" id="city" placeholder="city"   required>
<br>
State: <input type="text" name="State" maxlength="2" id="state" placeholder="state" required>
<br>
Zip: <input type="text" name="Zip" maxlength="5" id="zip" placeholder="zip code" required>
<br>
Phone: <input type="text" name="Phone" minlength="7" id="phone" placeholder="(xxx) xxx-xxxx" required>
<br>
Email: <input type="text" name="Email" minlength="7" id="email"  placeholder="xxxx@email.com"
required>
<br>
<input type="submit" value="Add Client" name="addclient">
</form>
</div>

这是我的db_connection_clientinfo.php文件。

<?php

    $dbhost = "localhost";
    $dbuser = "root";
    $pass = "";
    $db = "FuelCalcDB";


    $conn = new mysqli($dbhost, $dbuser, $pass, $db) or die("Connect failed:  %s\n");
    if($conn === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
    }
    else {
    echo "Online";
    }

$first_name = $_POST['FirstName'];
$last_name = $_POST['LastName'];
$address = $_POST['Address'];
$city = $_POST['City'];
$state = $_POST['State'];
$zipcode = $_POST['Zip'];
$phone = $_POST['Phone'];
$email = $_POST['Email'];


    $query = "INSERT INTO clientInformation (firstname, lastname, address, city, state, zipcode, phone, email) VALUES('$first_name','$last_name','$address','$city','$state','$zipcode','$phone','$email')";

    $result = mysqli_query($conn, $query);

    if($result)
       {  
        echo "Records added Successfully.";
       } else{
         echo "ERROR";
    }
mysqli_close($conn);
?>

我不知道我要去哪里,但是当我选择添加客户端时,出现“找不到对象错误”

有人可以说明我的问题吗?谢谢

0 个答案:

没有答案