php - 将数据作为 php 变量插入到 table_name 中

标签 php mysql

我将表名作为 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."'

关于php - 将数据作为 php 变量插入到 table_name 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21084639/

相关文章:

php - curl -F 是什么意思? PHP Instagram

mysql - #1111 - 组功能使用无效。我似乎不明白出了什么问题

mysql - 索引-mysql工作台的问题

php - 二叉树算法(不同方法)

php - Laravel 中 3 个表的复杂 INNER JOIN Mysql 查询

php - 运行一堆查询后,表不断崩溃

php - Laravel:如何验证所需的子数组项是否存在?

PHP 获取年龄函数在 Codeigniter 上不起作用

mysql - 从 A 表中的数据中选择,在 B 表中没有匹配项

php - 验证码解码