insert - 表中未记录的字段

发布于 2024-10-07 08:11:22 字数 346 浏览 6 评论 0原文

INSERT INTO `jos1_content` 
  (`title`, `introtext`, `fulltext`, `state`, `sectionid`, `catid`, `attribs`)
VALUES  
  ($title, $introtext, $fulltext, 1, 1, $catid, 5)

查询由 php 脚本组成。变量的推导表明它们不为空。 在 phpMyAdmin 的请求下显示错误:

1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 ' 附近使用的正确语法

INSERT INTO `jos1_content` 
  (`title`, `introtext`, `fulltext`, `state`, `sectionid`, `catid`, `attribs`)
VALUES  
  ($title, $introtext, $fulltext, 1, 1, $catid, 5)

Query is made up of php script. Derivation of variables shows that they are not empty.
At the request of phpMyAdmin shows the error:

1064 - 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 '

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

假扮的天使 2024-10-14 08:11:22

您需要使用单引号来指示 SQL 字符串 - 使用:

INSERT INTO `jos1_content` 
  (`title`, `introtext`, `fulltext`, `state`, `sectionid`, `catid`, `attribs`)
VALUES  
  ('". $title ."', '". $introtext ."', '". $fulltext ."', 1, 1, $catid, 5)

更安全的方法是使用:

$query = sprintf("INSERT INTO `jos1_content` 
                    (`title`, `introtext`, `fulltext`, `state`, `sectionid`, `catid`, `attribs`)
                  VALUES  
                   ('%s', '%s', '%s', 1, 1, %d, 5)",
        mysql_real_escape_string($title),
        mysql_real_escape_string($introtext),
        mysql_real_escape_string($fulltext),
        $catid);

参考:

You need to use single quotes to indicate strings to SQL - use:

INSERT INTO `jos1_content` 
  (`title`, `introtext`, `fulltext`, `state`, `sectionid`, `catid`, `attribs`)
VALUES  
  ('". $title ."', '". $introtext ."', '". $fulltext ."', 1, 1, $catid, 5)

A safer means would be to use:

$query = sprintf("INSERT INTO `jos1_content` 
                    (`title`, `introtext`, `fulltext`, `state`, `sectionid`, `catid`, `attribs`)
                  VALUES  
                   ('%s', '%s', '%s', 1, 1, %d, 5)",
        mysql_real_escape_string($title),
        mysql_real_escape_string($introtext),
        mysql_real_escape_string($fulltext),
        $catid);

Reference:

汹涌人海 2024-10-14 08:11:22

您需要用引号将要插入字符串类型字段的 PHP 变量引起来:

INSERT INTO `jos1_content` 
(`title`, `introtext`, `fulltext`, `state`, `sectionid`, `catid`, `attribs`)
VALUES  
('$title', '$introtext', '$fulltext', 1, 1, $catid, 5)

You need to surround your PHP variables that are being inserted into string-type fields with quotes:

INSERT INTO `jos1_content` 
(`title`, `introtext`, `fulltext`, `state`, `sectionid`, `catid`, `attribs`)
VALUES  
('$title', '$introtext', '$fulltext', 1, 1, $catid, 5)
写下不归期 2024-10-14 08:11:22

阅读您的编程语言手册中有关准备好的语句的信息或使用mysql_escape_string

Read about prepared statements in the manual of your programming language or use mysql_escape_string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文