gpt4 book ai didi

php - MySQL SQL语法错误;查看与您的 MySQL 服务器版本相对应的手册,了解要使用的正确语法

转载 作者:行者123 更新时间:2023-11-29 01:21:21 25 4
gpt4 key购买 nike

<分区>

我正在尝试将示例博客文章插入到我在 MySQL 中的“帖子”表中(使用 PHP),但是每当提交大字 rune 章时我都会收到语法错误。如果我提交 20 个字符的内容,它可以工作,但 500 个字符之类的内容会引发以下错误:

Error: 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 ''uid', 'username', 'p_date', 'title', 'content') VALUES('1','Mark Twain', '2014-' at line 1

“内容”将通过 varchar(1000) 变量插入到数据库中。该表在 mysql 中定义为:

CREATE TABLE posts
(
pid int NOT NULL AUTO_INCREMENT,
uid int NOT NULL,
username varchar(100) NOT NULL,
p_date date NOT NULL,
title varchar(225) NOT NULL,
content varchar(10000) NOT NULL,
PRIMARY KEY(pid),
FOREIGN KEY(uid) REFERENCES users(uid)
);

我尝试提交的实际内容是这样的:

Secondly, these missionaries would gradually, and without creating suspicion or exciting alarm, introduce a rudimentary cleanliness among the nobility, and from them it would work down to the people, if the priests could be kept quiet. This would undermine the Church. I mean would be a step toward that. Next, education -- next, freedom -- and then she would begin to crumble. It being my conviction that any Established Church is an established crime, an established slave-pen, I had no scruples, but was willing to assail it in any way or with any weapon that promised to hurt it. Why, in my own former day -- in remote centuries not yet stirring in the womb of time -- there were old Englishmen who imagined that they had been born in a free country: a "free" country with the Corporation Act and the Test still in force in it -- timbers propped against men's liberties and dishonored consciences to shore up an Established Anachronism with.

插入语句如下:

$sql = "INSERT INTO posts ('uid', 'username', 'p_date', 'title', 'content') VALUES('$uid','$uname', '$date', '$title', '$content')";

if(!mysql_query($sql,$con)){
echo "Oops! Something went wrong during the posting process. Please try again. ";
die('Error: ' . mysql_error($con));
header('Refresh: 1; URL=postingform.php');
}else{
// Now return the user to their post page
header('Refresh: 0; URL=postlist.php?uid='.$uid.'');
}

由于某种原因,它在 INSERT 过程中出错。我注意到的一件奇怪的事是日期在错误中被截断了。调用我正在使用的日期。 $date = date("Y-m-d");

我以前使用过相同的语法,没有出现任何问题。

****编辑

一些发贴者指出我的 INSERT 列语句中有单引号。我已将这些更改为支持抽动并完全删除它们,但错误仍然存​​在。

新错误:

Error: 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 's Court', 'Secondly, these missionaries would gradually, and without creating su' at line 1

我的插入语法仍然有问题,但我正在阅读的所有内容都表明它应该是正确的。

$sql = "INSERT INTO posts (`uid`, `username`, `p_date`, `title`, `content`) VALUES('$uid','$uname', '$p_date', '$title', '$content')";

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