gpt4 book ai didi

sql - insert - 表中未记录的字段

转载 作者:可可西里 更新时间:2023-11-01 07:46:13 26 4
gpt4 key购买 nike

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

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

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 '

最佳答案

您需要使用单引号向 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);

引用:

关于sql - insert - 表中未记录的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4419218/

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