connect_error); } $sql = "INSERT INTO tabl-6ren">
gpt4 book ai didi

PHP 和 MySQL 服务器错误

转载 作者:行者123 更新时间:2023-11-29 11:13:03 26 4
gpt4 key购买 nike

<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "myfirstdb";
$connect = new mysqli($host,$user,$pass,$db);
if ($connect->connect_error){
die("Connection failed: " . $connect->connect_error);
}

$sql = "INSERT INTO table1 (First Name, Last Name, Phone, E-Mail, Date) VALUES ('Doe', 'John', '0722222222', 'Doe_John@yahoo.com', '22/10/2016 18:00')";
if ($connect->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $connect->error;
}

$connect->close(); ?>

这是我的代码。它应该将数据添加到我已经使用 phpmyadmin 创建的数据库中。问题是每当我使用 localhost 启动代码时,我都会收到以下错误:

Error: INSERT INTO table1 (First Name, Last Name, Phone, E-Mail, Date) VALUES ('Doe', 'John', '0722222222', 'Doe_John@yahoo.com', '22/10/2016 18:00')

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Name, Last Name, Phone, E-Mail, Date) VALUES ('Doe', 'John', '0722222222', 'Doe_' at line 1


如果有人能帮助我那就太好了:D

最佳答案

您必须在字段名称前后添加 ``` 符号,这样查询就会像这样:

$sql = "INSERT INTO table1 (`First Name`, `Last Name`, Phone, `E-Mail`, Date) VALUES ('Doe', 'John', '0722222222', 'Doe_John@yahoo.com', '22/10/2016 18:00')";

如果你的表名没有特殊字符,“”空格属于它们,则可以跳过此步骤。

关于PHP 和 MySQL 服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40201798/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com