# 字段       类型               空    默认    1  id       int(10)             否    无    AUTO_INCREMENT  
  2  item_id  int(11)             否    无     
  3  item_id2 int(10)             是    NULL    
  4  title    varchar(100)        否    无   
  5  keywords varchar(20)         是    NULL      
  6  content  text                否    无      
  7  autor    varchar(25)         是    NULL
  8  clicks   int(10)             是    NULL      
  9  isdel    int(2)              否    0         
  10  issub   int(11)             否    0      
  11  time    datetime            否    无 
  12  style   int(2)              否    1      
  13  sourse  varchar(100)        是    NULL      
  14  xg_id   int(11)             是    NULL     
  15  is_vip  int(2)              否    0 这样一张articl表,如下插入语句,不知道哪里错了,求指点:mysql_query("insert into articl(item_id,item_id2,title,keywords,content,time,style,sourse,xg_id,is_vip) values ($item_id,$item_id2,'$title','$key','$content',now(),$style,'$resource',$xg_id,$is_vip)")or die(mysql_error());出错: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 ''啊啊吖','','啊啊吖',now(),1,'',,)' at line 1insert into articl(item_id,item_id2,title,keywords,content,time,style,sourse,xg_id,is_vip) values (1,,'啊啊吖','','啊啊吖',now(),1,'',,)

解决方案 »

  1.   

    mysql_query("insert into articl(item_id,item_id2,title,keywords,content,time,style,sourse,xg_id,is_vip) values ('$item_id', '$item_id2', '$title', '$key', '$content', now(), '$style', '$resource', '$xg_id', '$is_vip')") or die(mysql_error()); 
    不管是不是字符串类型的变量,都用单引号包围起来为妥
      

  2.   

    mysql_query("insert into articl(`item_id`,`item_id2`,`title`,`keywords`,`content`,`time`,`style`,`sourse`,`xg_id`,`is_vip`) values ($item_id,$item_id2,'$title','$key','$content',now(),$style,'$resource',$xg_id,$is_vip)")or die(mysql_error());加个 "`"符号试试,数字  1 左边的那个 符号
      

  3.   


    都用''后试了下,还是不行诶、、、
    insert into articl(item_id,item_id2,title,keywords,content,time,style,sourse,xg_id,is_vip) values ('1','','111','','1111',now(),'1','','','')Incorrect integer value: '' for column 'item_id2' at row 1
    item_id2明明是可以为空的,为什么提示不合法数据?
      

  4.   

    3 item_id2 int(10) 是 NULL 
    既然是int类型,那么默认值就应该是int,而不是null。
      

  5.   


    我把int型的都改为char型,就可以了,那为什么int型为空时 不能是null呢?我记得我们上课讲的是可以为空的啊
      

  6.   

    在低版本的mysql里才会允许 int DEFAULT null 这样的错误,就算int为空那么值也应该是0,NULL和INT是两种不同的类型。
      

  7.   

    不要这么改.....把你的sql echo出来就能看见错误
      

  8.   

    打印sql看看,这问题就出来了。
      

  9.   

    ...,now(),1,'',,)
    最后的 逗号两边对应的是
    xg_id,is_vip
    值呢,到哪去了?
    要写作
    ...,'$xg_id','$is_vip')
      

  10.   

    无论什么类型,你只要设置可以为 null,那么插入时,你就直接把为空的设为null就可以了