我真的很难在MySQL中插入多个记录。我使用的是这个参考资料:multiple.asp
这是我得到的错误:
错误:插入clk_9d0b4f116f_wp_comments (comment_post_ID,comment_author,comment_author_email,comment_author_url,comment_author_IP,comment_date,comment_date_gmt,comment_content,comment_karma,comment_approved,comment_agent,comment_type,comment_parent,user_id)值( '1','Ai',‘ai@aipresscoach.com’,'',‘:1’,'2017-06-01 19:49:15',在clk_9d0b4f116f_wp_comments (comment_post_ID,comment_author,comment_author_email,comment_author_url,comment_author_IP,comment_date,comment_date_gmt,comment_content,comment_karma,comment_approved,comment_agent,comment_type,comment_parent,user_id)中插入'2017-06-01 17:15‘,'0','1',’1‘,'','0',’2‘)值( '25','Ai',‘ai@aipresscoach.com’,'',‘:1’,'2017-06-01 19:49:15','2017-06-01 17:49:15','','0','1','0','2')
您的SQL语法出现了错误;请检查与MySQL服务器版本对应的手册,以获得在第16行“插入到clk_9d0b4f116f_wp_comments (comment_post_ID,comment_author,注释”)附近使用的正确语法。
下面是代码:
<?php
$servername = "xxxx";
$server_username = "xxxx";
$server_password = "xxxx";
$dbname = "xxxx";
$comment_id = 5;
$comment_id += 1;
$content = $_POST["blogPostPost"];// "this is the client answer";
$clientCur = $_POST["clientCurrent"];// "this is the client current
situation";
$clientAlt = $_POST["clientAlternative"];// "this is the client alternative
answer";
$title = "unity blog post";
$timelocal = date('Y-m-d H:i:s');
$timegmt = gmdate("Y-m-d H:i:s");
$table = "clk_9d0b4f116f_wp_comments";
// Create connection
$conn = mysqli_connect($servername, $server_username, $server_password,
$dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO $table (comment_post_ID, comment_author,
comment_author_email, comment_author_url, comment_author_IP, comment_date,
comment_date_gmt, comment_content, comment_karma, comment_approved,
comment_agent, comment_type, comment_parent, user_id)
VALUES (
'1',
'Ai',
'ai@aistresscoach.com',
'',
'::1',
'".$timelocal."',
'".$timegmt."',
'".$content."',
'0',
'1',
'',
'',
'0',
'2')";
$sql .= "INSERT INTO $table (comment_post_ID, comment_author,
comment_author_email, comment_author_url, comment_author_IP, comment_date,
comment_date_gmt, comment_content, comment_karma, comment_approved,
comment_agent, comment_type, comment_parent, user_id)
VALUES (
'25',
'Ai',
'ai@aistresscoach.com',
'',
'::1',
'".$timelocal."',
'".$timegmt."',
'".$clientCur."',
'0',
'1',
'',
'',
'0',
'2')";
if (mysqli_multi_query($conn, $sql)) {
echo "New records created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>任何意见和想法都是非常感谢的。亲切问候伊利亚斯
发布于 2017-06-01 18:37:03
您的查询可以是:
$sql = "
INSERT INTO $table
( comment_post_ID
, comment_author
, comment_author_email
, comment_author_url
, comment_author_IP
, comment_date
, comment_date_gmt
, comment_content
, comment_karma
, comment_approved
, comment_agent
, comment_type
, comment_parent
, user_id) VALUES
(1,'Ai','ai@aistresscoach.com','','::1','$timelocal','$timegmt','$content',0,1,'','',0,2),
(25,'Ai','ai@aistresscoach.com','','::1','$timelocal','$timegmt','$clientCur',0,1,'','',0,2);
";然后你就可以摆脱所有那些多查询的东西了。
发布于 2017-06-01 18:08:28
尝试用';‘来完成您的第一个$sql
$sql = "INSERT INTO $table (comment_post_ID, comment_author,
comment_author_email, comment_author_url, comment_author_IP, comment_date,
comment_date_gmt, comment_content, comment_karma, comment_approved,
comment_agent, comment_type, comment_parent, user_id)
VALUES (
'1',
'Ai',
'ai@aistresscoach.com',
'',
'::1',
'".$timelocal."',
'".$timegmt."',
'".$content."',
'0',
'1',
'',
'',
'0',
'2');";https://stackoverflow.com/questions/44314195
复制相似问题