簡體   English   中英

將數據作為php變量插入table_name

[英]Inserting data into table_name as php variable

我將表名作為php變量將數據插入表中。 但它給出了錯誤。 這里有什么不好的?

            if($flag == 1)
                $table = 'frrole_pupolar_article';
            else
                $table = 'frrole_category_article';
            $insertQuery1 = "INSERT INTO '.$table.' (`url`, `sentiment`, `category`, `title` ,`time`,`img_url`,`rt_count`,`tweet_count`) VALUES ('".$url."','".$setiment."','".$category."','".$title."','".$time."','".$img_url."','".$rt_count."','".$tweet_count."')";

錯誤:

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 ''.frrole_category_article.' (`url`, `sentiment`, `category`, `title` ,`time`,`im' at line 1
$insertQuery1 = "INSERT INTO '" .$table. "' (`url`, `sentiment`, `category`, `title` ,`time`,`img_url`,`rt_count`,`tweet_count`) VALUES ('".$url."','".$setiment."','".$category."','".$title."','".$time."','".$img_url."','".$rt_count."','".$tweet_count."')";

你錯誤地寫了'.$table.' 而不是'" .$table. "'

做就是了

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

刪除連接和單引號

如果你的字符串是$insertQuery1 = "INSERT INTO '.$table.' ( $insertQuery1 = "INSERT INTO '.$table.' (網址,情緒,你不能通過使用單引號'..'來逃避它

只做雙引號:

$insertQuery1 = "INSERT INTO ".$table." (`url`, `sentiment`, ....

為所有神聖,該死的使用{}if(){}語句,不使用它們是表現欠佳

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM