php 使用 MySQLi 将行插入 MySQL 数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15803853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:00:10  来源:igfitidea点击:

Insert row into MySQL database with MySQLi

phpmysqlmysqli

提问by user1734282

Can someone spot the mistake:

有人可以发现错误:

mysqli_query($connection, "INSERT INTO comments (event_id, fulltext, date_posted) VALUES (5, 'Hallo', 430234)");

The connection is established, but it just doesn't insert a new row.

连接已建立,但它只是不插入新行。

include("../../connect.php");

$event_id = intval($_GET["event_id"]);
$fulltext = $_GET["fulltext"];
$date = intval($_GET["date"]);

mysqli_query($connection, "INSERT INTO comments ('event_id', 'fulltext', 'date_posted') VALUES (5, 'Hallo', 430234)");

echo "INSERT INTO comments (event_id, fulltext, date_posted) VALUES (5, 'Hallo', 430234)";

mysqli_close($connection);

回答by Yogesh Suthar

FULLTEXTis reserved word in mysqlyou can't use it as column name use below query with `around column name

FULLTEXTmysql 中的保留字,您不能将其用作列名,在查询下方使用`周围列名

mysqli_query($connection, "INSERT INTO comments 
(`event_id`, `fulltext`, `date_posted`) VALUES (5, 'Hallo', 430234)");