0

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!

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
    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
    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
    Dec 13, 2018 at 0:02

1 Answer 1

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
));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.