if(isset($_POST['news_title']) && !empty($_POST['news_title'])){
$news_title=htmlspecialchars($_POST['news_title'],ENT_QUOTES);
$news_write=htmlspecialchars($_POST['news_write'],ENT_QUOTES);
$news_source=htmlspecialchars($_POST['news_source'],ENT_QUOTES);
$news_summary=htmlspecialchars($_POST['news_summary'],ENT_QUOTES);
$news_content=htmlspecialchars($_POST['news_content'],ENT_QUOTES);
$news_date=$_POST['news_date'];
$sql="insert into news set news_title='$news_title',news_write='$news_write',news_source='$news_source',news_summary='$news_summary',news_content='$news_content',news_date=$news_date";
$db->query($sql);
echo $db->insert_id;
echo $sql;数据无法插入,请问这是怎么回事?

解决方案 »

  1.   

    打印一下var_dump($db->query($sql));//看看是什么
      

  2.   

    还有你的sql语句写错了insert into tablename(....)values(....) 
      

  3.   

    $sql="insert into news set news_title='$news_title',news_write='$news_write',news_source='$news_source',news_summary='$news_summary',news_content='$news_content',news_date=$news_date";
        $db->query($sql);
    改为 
    $sql="update news set ....
      

  4.   

    插入的话应该这样写$sql="insert into news (news_title,news_write,news_source,news_summary,news_content,news_date)
    values('$news_title','$news_write','$news_source','$news_summary','$news_content',$news_date)"; 
      

  5.   


    插入的话应该这样写 $sql="insert into news (news_title,news_write,news_source,news_summary,news_content,news_date) 
    values('$news_title','$news_write','$news_source','$news_summary','$news_content',$news_date)"; 
    楼上也给出答案了.楼主,看一下sql的基础语句.
      

  6.   

    语法没有错
    6.4.3 INSERT 句法    INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
            [INTO] tbl_name [(col_name,...)]
            VALUES ((expression | DEFAULT),...),(...),...
            [ ON DUPLICATE KEY UPDATE col_name=expression, ... ]
    or  INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
            [INTO] tbl_name [(col_name,...)]
            SELECT ...
    or  INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
            [INTO] tbl_name
            SET col_name=(expression | DEFAULT), ...
            [ ON DUPLICATE KEY UPDATE col_name=expression, ... ]检查数据类型是否正确
    检查是否有遗漏的特殊字符
      

  7.   

    应该用update,update跟set是配对的