查询不起作用多列更新

时间:2016-05-30 12:25:38

标签: php mysql

你好我试图更新我的数据库用户离开,我想插入所有用户数据:野兔是我的脚本:

 $stmt = $connect->prepare("UPDATE users SET (
        userid,
        username,
        usertype,
        email,
        level,
        exp,
        money,
        ninjarank,
        avatar,
        village,
        clan,
        guild,
        healthpoint,
        chakrapoint,
        ninjutsu,
        taijutsu,
        genjutsu,
        senjutsu,
        talent,
        chakra,
        health,
        chakracontrol
        ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) WHERE userid= ?");
        $stmt->bind_param("isisiiisssssiiiiiiiiiii",
                     $userid,
                     $username,
                     $usertype,
                     $email,
                     $level,
                     $exp,
                     $money,
                     $ninjarank,
                     $avatar,
                     $village,
                     $clan,
                     $guild,
                     $healthpoint,
                     $chakrapoint,
                     $ninjutsu,
                     $taijutsu,
                     $genjutsu,
                     $senjutsu,
                     $talent,
                     $chakra,
                     $health,
                     $chakracontrol,
                     $userid
                         );
        $stmt->execute();
        $stmt->close();
        $connect->close();

但是这个查询根本没有工作得到任何结果,我设置了一个值+1000只是为了确保查询成功运行但数据库中的值是相同的请帮助这个查询

1 个答案:

答案 0 :(得分:1)

这是INSERT而非UPDATE语法,请使用以下格式:

UPDATE users u
SET u.username = ?,
    u.OtherColumn = ?,
    ......
WHERE u.user_id = ?

或者,如果您确实要插入,请将UPDATE替换为INSERT并删除WHERE子句。