繁体   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