duanhai7274 2018-11-28 20:38
浏览 31

将表单数据从用户插入数据库[重复]

This question already has an answer here:

I am currently trying to take information from a user text form and send it to my database. I am working with Xampp. Here is a snippet of my form to get the user data.

<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>

Here is my db_connection_clientinfo.php file.

<?php

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


    $conn = new mysqli($dbhost, $dbuser, $pass, $db) or die("Connect failed:  %s
");
    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);
?>

I don't know where i'm going wrong but when I select add client, I get an 'Object not found error'

Could someone please shed some light on my problem. Thank you

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Python报错怎么解决
    • ¥15 simulink如何调用DLL文件
    • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
    • ¥30 线性代数的问题,我真的忘了线代的知识了
    • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
    • ¥188 需要修改一个工具,懂得汇编的人来。
    • ¥15 livecharts wpf piechart 属性
    • ¥20 数学建模,尽量用matlab回答,论文格式
    • ¥15 昨天挂载了一下u盘,然后拔了
    • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题