[英]MYSQL & PHP No issue connecting with database but issue when posting into the DB
$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();
I've tried everything and I still get this error message:我已经尝试了所有方法,但仍然收到此错误消息:
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
The problem was with your single quotes (') and back-ticks (`) in your query.问题在于查询中的单引号 (') 和反引号 (`)。 Try using this below, I could not put it in comment尝试在下面使用它,我无法将其放在评论中
INSERT INTO `testdatabase`.`newuserformtable` ...
Database name or table name should not be considered as a string.不应将数据库名称或表名称视为字符串。
so the sql should be :所以sql应该是:
INSERT INTO testdatabase.newuserformtable (`First Name`,`Last Name`, `Title`)
VALUES ('John', 'Doe', 'john@example.com');
It seems error with single quote you mixed with您混合的单引号似乎有误
$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' (
First Name ,
Last Name ,
Title`) VALUES ('John', 'Doe', 'john@example.com')";
write like this problem with your quotes.....and also checkdatatype and length if there is another error post your error用你的引号写这个问题......如果还有另一个错误,还要检查数据类型和长度发布你的错误
You used a single quote( '
) instead of a backtick( `
) on the database and table name.您在数据库和表名上使用了单引号 ( '
) 而不是反引号 ( `
)。
$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";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.