gpt4 book ai didi

php - 插入网站帖子时mysql语法错误

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

我正在对网站的服务器端进行编码,并使用它来存储帖子

if(!(mysql_query("INSERT INTO `post-data`(`site`, `source`, `meta-desc`, `title`, `figure`, `post`,`date`, `tags`, `category`) VALUES ('$this->site','$url','$this->meta_desc','$this->title','$this->figure',htmlentities($this->body),NOW(),'','')"))){
echo mysql_error();
die("DB_in_post Error");}

我没有遇到任何问题,因为当我测试示例帖子时,我遇到了 mysql 语法错误

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 '

as a person ' at Line 20

当我使用 htmlentities 时,我看到此错误

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 'hello', 'world', 'foo' => 'bar');

if you want' at line

Post_Link这是帖子中犯错误的部分的图像,该帖子是关于编码的

那么知道我应该做什么吗?

最佳答案

看起来像是对 htmlentities() 调用的引用问题(我将其更改为 mysql_real_escape_string())

"INSERT INTO `post-data`
(`site`, `source`, `meta-desc`, `title`, `figure`, `post`,`date`, `tags`, `category`)
VALUES (
'$this->site',
'$url',
'$this->meta_desc',
'$this->title',
'$this->figure',
'" . mysql_real_escape_string($this->body) ."',
NOW(),
'',
''
)"

关于php - 插入网站帖子时mysql语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14712109/

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