Brad
Brad

Reputation: 417

MySQLi Not Changing Database Variables Properly

I'm currently creating a ban form that bans users through the MySQLi database, however currently when I try to ban them, the 'active' changes to 0 as opposed to 2 and the banreason does not get updated... Here is the code

$qry = "UPDATE members SET active = '2' AND breason = '".$_POST['reason']."' WHERE login =  '".$_POST['login']."'";
$result = @mysqli_query($GLOBALS["___mysqli_ston"], $qry);
if($result) {
    header("location: banneduser?login=$login&reason=$reason");
    exit();
}else {
    die("Error:".((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
}

I am not receiving any error on the page.

Upvotes: 0

Views: 48

Answers (1)

Lepidosteus
Lepidosteus

Reputation: 12027

Despite the fact that given the comments your code is insecure and you are ok with that, columns to be updated should not be separated by the AND operator in an UPDATE statement.

UPDATE [LOW_PRIORITY] [IGNORE] table_reference
    SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
    [WHERE where_condition]
    ...

Replace your AND with a comma.

Upvotes: 1

Related Questions