I've read this thread: Issues incrementing a field in MySQL/PHP with prepared statements but didn't see the answer to my problem.
PDOStatement Object
(
[queryString] => UPDATE user_alerts SET notif = ? + 2 WHERE ( user_id = ? )
)
$stmt->execute( array( 'notif', '1' ) );
As far as I can tell, all this is correct.
When the above code executes, it sets the notif column equal to 2 irregardless of what the value of the notif column is. It's as if the SQL is reading like SET notif = 2
instead of SET notif = notif + 2
I haven't been able to figure it out and would really appreciate help!
$sql = 'UPDATE user_alerts SET notif = notif + 2 WHERE ( user_id = :userid )';
$prepStatement = $pdo->prepare( $sql );
$prepStatement->execute(array(':userid' => $userid));
You can't bind a column name to a prepared statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With