doukai2839 2015-05-07 12:27
浏览 82
已采纳

在第1行'group ='1'WHERE id = 6'附近的MySQL语法错误

I have a pretty simple task I want to perform, when I run the code one way it's fine, if I run it another way Fatal error: Uncaught exception 'Exception'...

Works

if (Input::get('userid')) {

    $user_id = Input::get('userid');

    $user->find($user_id);

    $name = $user->data()->first_name;


    if ($user->data()->active == 1) {

        $user->update(array(
            'active' => 0
        ));

        Session::flash('userboard', $name.' Deactivated');
        Redirect::to('admin.php');

    } else {

        $user->update(array(
            'active' => 1
        ));

        Session::flash('userboard', $name.' Activated');
        Redirect::to('admin.php');

    }

}

Doesn't Work

if (Input::get('adminid')) {

    $user_id = Input::get('adminid');

    $user->find($user_id);

    $name = $user->data()->first_name;

    if ($user->data()->active == 1) {

        $user->update(array(
            'group' => 1
        ));

        Session::flash('userboard', $name.' Deactivated');
        Redirect::to('admin.php');

    } else {

        $user->update(array(
            'group' => 2
        ));

        Session::flash('userboard', $name.' Activated');
        Redirect::to('admin.php');

    }

}

No matter which way I change it around I can't update the group. They are both int(11) in MySQL. I'm almost wondering if I need to delete the column and re add it? This group value is used for setting user permissions if that's of any help.


PDO errorInfo

Array ( [0] => 42000 [1] => 1064 [2] => 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 'group = '1' WHERE id = 6' at line 1 )

  • 写回答

1条回答 默认 最新

  • dtv55860 2015-05-07 12:43
    关注

    Your framework, or class, isn't putting ticks around the column. Group is a reserved keyword in MySQL (and probably every DBMS), so the column must be quoted with backticks: `group`

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源