简体   繁体   中英

Inserting Form Data into SQL table

I've been trying to figure this out for hours and it seems like there are multiple ways of doing it but for some reason I can't seem to get it to work correctly. For some reason my table is being updated and I am only seeing new rows with a new auto increment integer but the remaining columns are left blank. There is a bit more to that form but I left it off to keep this as short as possible. Thanks for the help!

File: 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";

File with form:

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

I have Just Edited your sql a little bit. Try It

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM