2010-01-23 133 views
1

我绝不经历了MySQL和不断收到错误代码这样的行:神秘MySQL错误

$sql= "INSERT INTO songs (unique_show_id, artist, date, year, city, state, venue, taper, transfered_by, source, mic_loc, lineage, uploaded_by, uploaded_on, show_notes, show_xml) 
      VALUES('$showId', '$artist', '$showDate', '$year, '$city', '$state', '$venue', '$taper', '$transferer', '$source', '$mic_loc', '$lineage', '$uploader', NOW(), '$show_notes', '$show_xml')";  

//check to see if the query went through 
      if (!mysql_query($sql,$con)){ 
       echo "query fail"; 
      die('Error: ' . mysql_error()); 
    } 

我敢肯定它的东西简单,但我不能看到那里的错误是。该错误消息我得到的是:

query failError: 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 'ipuhgbi', 'CA', '', '', '', '', '', '', 'danwoods', NOW(), '', '<show id=\'gm198' at line 2 

一些我插入值是NULL,但是从我读过,我不认为这应该是一个问题。有任何想法吗?

+0

显示替换的查询。 – 2010-01-23 06:20:18

+0

请在MySQL中发布'DESCRIBE SONGS'的输出,以便我们可以看到每列的数据类型。 – 2010-01-23 06:25:39

回答

0

它看起来像错误行上的最后一个单引号不会被转义。

您需要记住清理所有进入查询的字符串。

0

有你需要把握相当几件事:

  1. 你不通过查询插入主键(例如unique_show_id在你的代码)
  2. 对于数字你不使用单引号。
  3. 这是更好地使用插入记录其避免了如计数问题集变种:对数字
  4. 使用INTVAL和mysql_real_escaps_string字符串,以避免注射问题以及单引号查询错误回报。

    插入到表组字段= 'FIELD_VALUE',FIELD2 = 'FIELD_VALUE' //等

4

$year后缺少引号。

当MySQL发出这样的错误(接近bla di bla)时,错误通常在它提到的字符串之前。在这种情况下,'ipuhgbi'映射到$ city,所以你知道它在'$ city'之前,我们在那看到什么?瞧,一个缺少的报价。