将表单数据插入sql表

gcuhipw9  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(433)

我已经试着弄清楚这几个小时,它似乎有多种方法来做这件事,但由于某种原因,我似乎不能让它正常工作。由于某些原因,我的表正在更新,我只看到新行具有一个新的自动递增整数,但其余列留空。有一点更多的形式,但我离开了它保持这个尽可能短。谢谢你的帮助!
文件:dbh.inc.php

$dbServername = "localhost";
$dbUsername = "username";
$dbPassword = "password";
$dnName = "database_name";

$conn = mysqli_connect($dbServername, $dbUsername, 
$dbPassword, $dnName);
if(!$conn)
// creation of the connection object failed
die("connection object not created: ".mysqli_error($conn));
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";

文件格式:

$name7 = $_POST['name7'];
$email7 = $_POST['email7'];
$phone7 = $_POST['phone7'];
$message7 = $_POST['message7'];

$sql = "INSERT INTO user_contacts (name7, email7, phone7, message7) VALUES ('".$_POST["name7"]."','".$_POST["email7"]."','".$_POST["phone7"]."','".$_POST["message7"]."')"; 
mysqli_query($conn, $sql);
 ?>
            <div class="form-group">
                <form action="dbh.inc.php" method="POST">
                <input type="text" class="form-control" name="name7" id="name7" placeholder="<?php esc_html_e('Name:','listingpro'); ?>">
                <span id="name7"></span>
            </div>

            <div class="form-group form-group-icon">
                <i class="fa fa-envelope" aria-hidden="true"></i>
                <input type="email" class="form-control" name="email7" id="email7" placeholder="<?php esc_html_e('Email:','listingpro'); ?>">

            </div>

            <div class="form-group">
                <input type="text" class="form-control" name="phone7" id="phone7" placeholder="<?php esc_html_e('Phone','listingpro'); ?>">
                <span id="phone7"></span>
            </div>

            <div class="form-group">
                <textarea class="form-control" rows="5" name="message7" id="message7" placeholder="<?php esc_html_e('Message:','listingpro'); ?>"></textarea>
            </div>
trnvg8h3

trnvg8h31#

我刚刚编辑了你的sql。试试看

$sql = "INSERT INTO user_contacts (name7, email7, phone7, message7) VALUES ('". 
      $name7. "','" . $email7 .  "','". $phone7 ."','". $message ."')";

相关问题