包含数字的 PHP 插入语句是错误的


PHP insert statement containing numbers is wrong

我得到了这个陈述:

   $query="INSERT INTO error_report(task_id,url_is_route, forbidden_word, google_host_fail, google_cache_fail, google_title_fail, google_element_fail, robots_noindex_nofollow, xrobots_noindex_nofollow, title_fetch_warn, h1_fail,h2_fail,h3_fail ,h1_warn ,h2_warn, h3_warn)
         VALUES (".$this->task_id.",0,0,0,0,0,0,0,0,0,0,0,0,0,0)";   

mysql_query($query) or die(mysql_error()); 

我明白这个:

您的 SQL 语法有误;请查看手册 对应于您的MySQL服务器版本,以便使用正确的语法 接近第 2 行的"

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)"

问题出在哪里?

更新

$query="INSERT INTO error_report(task_id,url_is_route, forbidden_word, google_host_fail, google_cache_fail, google_title_fail, robots_noindex_nofollow, xrobots_noindex_nofollow, title_fetch_warn, h1_fail,h2_fail,h3_fail ,h1_warn ,h2_warn, h3_warn)
             VALUES ('".$this->task_id."','0','0','0','0','0','0','0','0','0','0','0','0','0','0')"; 

现在我得到:

整数值不正确:"表示第 1 行的列"task_id"

  1. 使用引号
  2. 您正在尝试更新 16 列,但仅输入 15 个值。纠正这一点。

整数值不正确:"表示第 1 行的列"task_id"

$this->task_id是空的,不包含您怀疑的 116。

如何将字段的默认值设置为 0 并执行以下操作:


$query="INSERT INTO error_report(task_id) VALUES (".$this->task_id.")";   

检查这些

  1. $this->task_id 包含值而不是空
  2. $this->task_id 中包含整数值或任何字符。我认为该列是 int,因此如果它包含非整数值,则会抛出错误