$sql = "INSERT INTO 'testdatabase`.`newuserformtable' (`First Name`,`Last Name`, `Title`)
VALUES ('John', 'Doe', 'john@example.com')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
我已经尝试了所有方法,但我仍然得到这个错误信息:
Connected successfullyError: INSERT INTO 'testdatabase`.`newuserformtable`(`First Name`, `Last Name`, `Title`) VALUES ('John', 'Doe', 'john@example.com')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''testdatabase`.`newuserformtable' (`First Name`, `Last Name`, `Title`) VALUES ' at line 1
问题是您的查询中的单引号(')和反引号(')。试试下面这个,我不能把它放在注释
INSERT INTO `testdatabase`.`newuserformtable` ...
数据库名或表名不应被视为字符串。
所以SQL应该是:
INSERT INTO testdatabase.newuserformtable (`First Name`,`Last Name`, `Title`)
VALUES ('John', 'Doe', 'john@example.com');
似乎是单引号错误,你混合了
$sql = "INSERT INTO `testdatabase`.`newuserformtable' (`First Name`,`Last Name`, `Title`)
VALUES ('John', 'Doe', 'john@example.com')";
$sql =" INSERT INTO testdatabase
. "newuserformtable' (
名字,
姓氏,
头衔VALUES ('John', 'Doe', 'john@example.com')";
用你的引号写这个问题.....还有checkdatatype和length如果有其他错误,请发布错误
在数据库和表名上使用了单引号('
)而不是反引号(`
)。
$sql = "INSERT INTO `testdatabase`.`newuserformtable`
(`First Name`,`Last Name`, `Title`)
VALUES
('John', 'Doe', 'john@example.com')";
$sql = "INSERT INTO `testdatabase`.`newuserformtable'
(`First Name`,`Last Name`, `Title`)
VALUES
('John', 'Doe', 'john@example.com')";
$res = mysql_query($sql);
if ($res) {
echo "New record created successfully";
}
else {
echo "Error";
}