Update multiple columns on a database using meta keys and meta values

I am trying to update multiple fields in a database using their respective meta key but it doesn’t work. It works only when I update them one at a time. How do I get this to work?

Below works:
$sql = "UPDATE wp_usermeta SET meta_value = '$meta_value' WHERE meta_key = '$meta_key' AND user_id= $user_ID";

Below does not work:
$sql = "UPDATE wp_usermeta SET (meta_value = '$meta_value', meta_key = '$meta_key'), (meta_value = 'The freak I wants', meta_key = 'on_the_weekends_i' WHERE user_id= $user_id)";

I don’t see the point of second query, you are trying to update same table rows twice for specific ID.

I am trying to update the database after the user clicks on “save” and there are multiple fields

Aren’t the closing brackets on the second pair in the wrong place, should be before the WHERE clause? What happens when you try that query in phpmyadmin?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.