使用MYSQL和PHP动态更新菜单

时间:2017-06-24 18:26:06

标签: php mysql

我通过XAMPP运行MYSQL和PHP来创建CMS - 学习了很多,但我对此错误感到非常困惑。

The information was not accepted
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1, visible = 1 WHERE id = 1' at line 3

因此,当我通过PHPMyAdmin更新菜单项时,它显示了这个

UPDATE `information` SET `menu` = 'Changed Menu Name' WHERE `information`.`id` = 1;

我的相关PHP会是,或查看我Gist上的整个文件:

        if (empty($errors)){
            $id = mysql_prep($_GET['info']);
            $menu = mysql_prep($_POST['menu']); //use POST array for form method
            $position = mysql_prep($_POST['position']);
            $visible = mysql_prep($_POST['visible']);

            $query = "UPDATE information SET 
                menu = '{$menu}', 
                position = {$position}, 
                visible = {$visible} 

                 WHERE id = {$id}";

            $result = mysql_query($query, $connection);

            if (mysql_affected_rows() == 1 ) {
                //Successful
                $message = "The information was correctly updated";
            } else {
                //Failure
                $message = "The information was not accepted";
                $message .= "<br>" . mysql_error();
            }

        } else {
            //Errors are happening
            $message = "There were " . count($errors) . " too many errors in the form";
        }

    }

我尝试在我的if(mysql_affected_rows()== 1)中添加 $ connection 变量并更新MySQL代码以包含空格。我还尝试在WHERE

之后添加 $ id 变量

我对如何解决此错误感到很困惑。有关更多上下文,可以找到项目的仓库here

真正接近拥有动态菜单 - 任何帮助都会很棒!

0 个答案:

没有答案