将值插入表失败

时间:2014-01-17 19:20:19

标签: php mysql sql

    function db_insert_article($flag,$url,$sentiment,$category,$title,$time,$rt_count,$tweet_count,$img_url)
    {
                    $con = mysqli_connect('127.0.0.1', 'root', '', 'mysql');
                    if (mysqli_connect_errno())
                    {
                        echo "Failed to connect to MySQL: " . mysqli_connect_error();
                        return;
                    }
                $today = date("Ymd"); 

    $insertQuery1 = "INSERT INTO frrole_popular_article (`url`, `sentiment`, `title` , `time` , `img_url` , `rt_count` , `tweet_count`, `today`) VALUES ('".$url."','".$sentiment."','".$title."','".$time."','".$img_url."','".$rt_count."','".$tweet_count."','".$today."')";
                        if (!mysqli_query($con,$insertQuery1))
                        {
                            //die('Error: ' . mysqli_error($con));
                        }
 }

TAble结构:

Image

一切都很好看。那么为什么它不插入表?在此之下,我有其他查询成功插入表中。 IT也没有显示任何错误。

UPdate1 :此查询工作正常,就在上面的代码

之下
            $insertQuery2 = "INSERT INTO frrole_article_sentiment (`url`, `sentiment`, `category`, `title` , `time` , `img_url` , `rt_count` , `tweet_count`, `today`) VALUES ('".$url."','".$sentiment."','".$category."','".$title."','".$time."','".$img_url."','".$rt_count."','".$tweet_count."','".$today."')";

            if (!mysqli_query($con,$insertQuery2))

            {

                //die('Error: ' . mysqli_error($con));

            }

UPDATE2

$insertQuery1 = "INSERT INTO frrole_popular_article (`url` , `sentiment`, `img_url` , `title` , `rt_count` , `tweet_count`, `time` , `today`) VALUES ('".$url."','".$sentiment."','".$img_url."','".$title."','".$rt_count."','".$tweet_count."','".$time."','".$today."')";

1 个答案:

答案 0 :(得分:0)

您正尝试插入:

$insertQuery2 = "INSERT INTO frrole_article_sentiment
     (`url`, `sentiment`, `category`,
      `title` , `time` , `img_url` ,
    `rt_count` , `tweet_count`, `today`) 
        VALUES ....

但是当你制作select * from frrole_article_sentiment;时,它会返回8列,你试图插入9列,换句话说就是你想要插入insert into....属性的州CATEGORY但它不存在于表