this query works:
$player_id = $_POST['player_id'];//array
$ids = explode(',',$player_id);
$in = implode(',', array_fill(0, count($ids), '%d'));
$wpdb->query($wpdb->prepare("DELETE FROM {$player_table} WHERE id IN ($in)", $ids));
this does not:
$disabled = $_POST['disabled'];
$media_id = $_POST['media_id'];//array
$ids = explode(',',$media_id);
$in = implode(',', array_fill(0, count($ids), '%d'));
$wpdb->query($wpdb->prepare("UPDATE {$media_table} SET disabled = %s WHERE id IN ($in)", $disabled, $ids));
I cant figure out why.
CodePudding user response:
You need to spread the IDS into separate arguments to match all the %s
in the query. Use ...
syntax to do this.
$wpdb->query($wpdb->prepare("UPDATE {$media_table} SET disabled = %s WHERE id IN ($in)", $disabled, ...$ids));