I can't figure out what's wrong with this statement. $wpdb->query update

admin2025-06-05  3

I'm trying to use the $wpdb-query method, but can't seem to get it to work.

I get a 500 error when I try the following:

$update_status = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}wcpv_commissions SET commission_status = '".$status."' WHERE vendor_id = '".$vendor_id."' AND order_date BETWEEN '".$date1."' AND '".$date2."'"));

Is there something I am missing here. I have not used $wpdb much, so am sure I must be missing something.

I appreciate any help here.

Thanks!

I'm trying to use the $wpdb-query method, but can't seem to get it to work.

I get a 500 error when I try the following:

$update_status = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}wcpv_commissions SET commission_status = '".$status."' WHERE vendor_id = '".$vendor_id."' AND order_date BETWEEN '".$date1."' AND '".$date2."'"));

Is there something I am missing here. I have not used $wpdb much, so am sure I must be missing something.

I appreciate any help here.

Thanks!

Share Improve this question edited Dec 12, 2018 at 23:45 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Dec 12, 2018 at 23:34 TaphaTapha 1034 bronze badges 3
  • Have a look at the documentation for how to use prepare properly. If you enable debugging you will likely see an error message. – Milo Commented Dec 12, 2018 at 23:44
  • Where are you running this code? It's difficult to tell what could be wrong when you've shown a single line, can you provide more code context? E.g. it could be related to global variables but without seeing more context it's impossible to tell. It could also be that you're trying to call it in a standalone file you're loading directly, but again, impossible to tell with the information available. Also, what are you trying to do? Something involving commissions – Tom J Nowell Commented Dec 13, 2018 at 0:00
  • Also, 500 error is just the servers way of saying something went wrong in PHP, we don't know what it was, check the PHP error log for the real error message. Can you look up your PHP error log to find that error message? – Tom J Nowell Commented Dec 13, 2018 at 0:02
Add a comment  | 

1 Answer 1

Reset to default 4

Without an error message, it is difficult to tell the exact problem. It is important to debug within WordPress and check your webserver error logs.

One problem is your call of prepare(). The method takes 2 or more arguments, you only passed 1. Instead try the following

$update_status = $wpdb->query($wpdb->prepare(
    "UPDATE {$wpdb->prefix}wcpv_commissions SET commission_status = %s WHERE vendor_id = %d AND order_date BETWEEN %s AND %s",
    $status,
    $vendor_id,
    $date1,
    $date2
));
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749104223a316395.html

最新回复(0)