用于更新条目的Mysql查询不起作用

时间:2015-07-07 10:48:13

标签: php mysql

$parameter = $_GET["o"];                                                            

$result = decode($password, $parameter, $salt);                      


if (strtolower($result['statusmessage']) == 'ok') {                                     
    $uservar = $result['id'];                                            

    print PHP_EOL . $uservar . PHP_EOL; 
    print PHP_EOL . $vipstatus . PHP_EOL; 
    print PHP_EOL . $callstatus . PHP_EOL; 

    $conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);

    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    } 

    $sql = "UPDATE user SET vipstatus='1', SET callstatus='1' WHERE username ='$uservar'";

    print PHP_EOL . $sql . PHP_EOL; 

    if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
    } else {
    echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $conn->close(); 
    }
?>

到目前为止,用户的vipstatus设置为1,但是callstatus设置为0,我希望它也是1。我做错了什么?

3 个答案:

答案 0 :(得分:2)

错误在查询中,使用 SET 关键字一次:

 $sql = "UPDATE user SET vipstatus='1', callstatus='1' WHERE username ='$uservar'";

答案 1 :(得分:2)

查询中不需要两次SET,如下所示: -

 $sql = "UPDATE user SET vipstatus='1',callstatus='1' WHERE username ='$uservar'";

注意: - SET只需在更新查询中使用一次。

答案 2 :(得分:0)

将此更改为

$sql = "UPDATE user SET vipstatus='1', SET callstatus='1' WHERE username ='$uservar'";

$sql = "UPDATE user SET vipstatus='1',  callstatus='1' WHERE username ='$uservar'";

注意

UPDATE user SET vipstatus='1', callstatus='1', WHERE username此行不起作用。 s='1', WHERE的Cz,你可以看到(,)逗号。

基本上都是这样做的错误。所以在被击中之前先学习它。