Altin
Altin

Reputation: 2245

PDO Query Update with multi conditions?

I need your help with a little problem that has caused me to get stuck on that project for 2 days now.

I have a query like this:

UPDATE table SET name='$name', surname='$surname'
WHERE cid=$cid AND counter=$count";

and I need to write it in PDO syntax. Now, I know how to do it with one condition but I cant get it to work with multi-conditions (like WHERE cid=$cid AND counter=$count)

Can someone help me out how to make this work if i have more than one condition on the query?

Thanks.

Upvotes: 1

Views: 1697

Answers (1)

James
James

Reputation: 255

Try this, I think it should work:

$query = "UPDATE table SET name='$name', surname='$surname' WHERE cid = :cid AND counter = :counter";
$stmt = $db->prepare($query);
$stmt->BindValue(':cid', $cid, PDO::PARAM_STR);
$stmt->BindValue(':counter', $counter, PDO::PARAM_STR);
$stmt->execute();

Edit: $db is where you call your function to connect to your database.

Upvotes: 4

Related Questions