I am trying to update some values in a table via MySQL and php, but I cannot it to work: Here is my code:
$update = "UPDATE $table
SET `active`='1' AND `title`='Disabled By Moderator'
WHERE `id`='".$ad_id."' LIMIT 1";
I am trying to update some values in a table via MySQL and php, but I cannot it to work: Here is my code:
$update = "UPDATE $table
SET `active`='1' AND `title`='Disabled By Moderator'
WHERE `id`='".$ad_id."' LIMIT 1";
when updating multiple columns, separated it with a comma.
$update = "UPDATE $table SET `active`='1' , `title`='Disabled By Moderator' WHERE `id`='".$ad_id."' LIMIT 1";
the reason why it is updating 1
or 0
on column active
is because the statement is performing boolean operation. The only column that is affected on your current statement is only column Active
. Column title
is part of the boolean operation.
Your update statement will look like if it is grouped,
UPDATE $table
SET active = (1 AND (title = 'Disabled By Moderator'))
WHERE id= 'val'
LIMIT 1
As a sidenote, the query is vulnerable with SQL Injection
if the value(s) of the variables came from the outside. Please take a look at the article below to learn how to prevent from it. By using PreparedStatements
you can get rid of using single quotes around values.