rps*_*ep2 1 php mysql sql sql-insert
我正在尝试将数据插入到我的 MySQL 表中,但没有成功。我的代码看起来像:
$mysqli = mysqli_connect("localhost","login info");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
if (isset($_POST['submit'])) {
$number = $_POST['number'];
$road = $_POST['road'];
$postcode=$_POST['postcode'];
$price=$_POST['price'];
$type=$_POST['type'];
$bedrooms=$_POST['bedrooms'];
$agent=$_POST['agent'];
$featured=$_POST['featured'];
$keywords=$_POST['keywords'];
$mysqli->query("
INSERT INTO listings-rent
(number, road, postcode, price, type, bedrooms, agent, featured, keywords)
VALUES
('$number','$road','$postcode','$price','$type','$bedrooms','$agent','$featured','$keywords')");
}
Run Code Online (Sandbox Code Playgroud)
连接正常,没有返回错误。
您的表名应该用反引号括起来,因为它包含非字母数字字符。
INSERT INTO `listings-rent` (...) VALUES (...)
Run Code Online (Sandbox Code Playgroud)
并且还请对这些值进行参数化。