简体   繁体   English

无法通过PHP将新数据插入数据库

[英]Unable to insert new data into database via PHP

I am unable to store new data into the database after the user submits the form. 用户提交表单后,我无法将新数据存储到数据库中。 I check the database table via phpMyAdmin, but I do not see any new data. 我通过phpMyAdmin检查数据库表,但是没有看到任何新数据。 Can anyone show me the mistake in my code. 谁能告诉我我代码中的错误。

HTML code (listing.html): HTML代码 (listing.html):

<html>
    <form action="confirm_listing.php" method="POST">
        <input name="Firstname" placeholder="Firstname">
        <input name="Lastname" placeholder="Lastname">
        ...
        <input type="submit" value="Submit">
    </form>
</html>

php code (confirm_listing.php): php代码 (confirm_listing.php):

<?php
    $firstname = $_POST['Firstname'];
    $lastname = $_POST['Lastname'];
    $address = $_POST['Address'];
    $suburb = $_POST['Suburb'];
    $city = $_POST['City'];
    $type = $_POST['Type'];
    $room = $_POST['Room'];
    $floorArea = $_POST['Floor'];
    $landArea = $_POST['Land'];
    $price = $_POST['Price'];
    $contact = $_POST['Contact'];
    $active = "1";

    $server = "localhost";
    $dbusername = "root";
    $dbpassword = "";
    $dbname = "summitrealestatedb";

    $connection = mysqli_connect($server, $dbusername, $dbpassword, $dbname);

    if (!$connection) {
        die("Connection failed: " . mysqli_connect_error());
    }

    $sql = "INSERT INTO property (firstname, lastname, address, suburb, city, type, room, floor, land, price, contact, active) VALUES ('$firstname', '$lastname', '$address', '$suburb', '$city', '$type', '$room', '$floorArea', '$landArea', '$price', '$contact', '$active');";
    mysqli_query($connection, $sql);

    mysqli_close($connection);
?>

Here is a picture of what it currently looks like in the database table: 这是数据库表中当前外观的图片

instead of 代替

<?php
    $firstname = $_POST['Firstname'];
    $lastname = $_POST['Lastname'];
?>

use 采用

<?php
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
?>


use the name that you have assigned to the name not to the placeholder 使用您分配给名称的名称而不是占位符

尝试打印插入错误

 mysqli_query($connection, $sql) or die(mysqli_error($connection));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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