用户提交表单后,我无法将新数据存储到数据库中。我通过phpMyAdmin检查数据库表,但我没有看到任何新数据。任何人都可以在我的代码中向我显示错误。
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代码(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);
?>
以下是数据库表中目前的a picture:
答案 0 :(得分:1)
而不是
<?php
$firstname = $_POST['Firstname'];
$lastname = $_POST['Lastname'];
?>
使用
<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
?>
使用您为名称指定的名称而不是占位符
答案 1 :(得分:1)
尝试打印插入错误
mysqli_query($connection, $sql) or die(mysqli_error($connection));