Php 错误1064 I您的SQL语法有错误;

Php 错误1064 I您的SQL语法有错误;,php,mysql,joomla3.0,Php,Mysql,Joomla3.0,嗨,我在将数据插入数据库时出错: 1064您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 第3行的“用户,您好,2017-03-30 10:42:43,0)”附近SQL=INSERT INTO #uu注册表项(名称,类型,日期,已发布) 数值(超级用户,你好,2017-03-30 10:42:43,0) 我的代码: $greating1=$this->item->greeting; $datetime = new J

嗨,我在将数据插入数据库时出错:

1064您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 第3行的“用户,您好,2017-03-30 10:42:43,0)”附近SQL=INSERT INTO
#uu注册表项
名称
类型
日期
已发布
) 数值(超级用户,你好,2017-03-30 10:42:43,0)

我的代码:

$greating1=$this->item->greeting;
                $datetime = new Jdate('now + 1 hour'); //GTM hour Lisbon
                $this->item->menssage1 = $datetime;
                //session portection
                $user = JFactory::getUser();
                if($user->guest)
                {
                    $this->item->menssage2 = "You are not allowed to enter this site";
                }
                else
                {
                    $username = $user->name;
                    $this->item->menssage2 = $username;
                    $db1 = JFactory::getDbo();
                    $query1 = $db1->getQuery(true);

                    // Insert columns.
                    $columns = array('name', 'type_entry', 'date_regist', 'published');


                    // Insert values.
                    $values = array($username, $greating1, $datetime, 0);

                    // Build the query
                    $query1
                    ->insert($db1->quoteName('#__registentrys'))
                    ->columns($db1->quoteName($columns))
                    ->values(implode(',', $values));

                    $db1->setQuery($query1);    
                    $db1->execute();

提前感谢您的回答。

文字值必须在引号内

 SQL=INSERT INTO `#__registentrys` (`name`,`type_entry`,`date_regist`,`published`) 
 VALUES ( 'Super User', 'hello', '2017-03-30 10:42:43',0) 

否则将假定为列名

很容易在值上加引号

->values(implode(',', $db1->quote($values)));

Joomla数据库使用$db->quote保存字符串,否则它将假定值为列。因此,您需要按照joomla语法这样更改查询。 这条线

 $values = array($username, $greating1, $datetime, 0);
需要改成

 $values = array($db1->quote($username), $db1->quote($greating1), $db1->quote($datetime), 0);

也许
$values_quoted=“””。内爆(“,”,$value)。"'";->值($values_quoted)请注意,如果字符串本身中有引号,则此窗台可能会有问题,因此需要对其进行转义。谢谢,但我通过简单使用:->值(内爆(',',$db1->quote($values));