最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin10PV0评论

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
));
Post a comment

comment list (0)

  1. No comments so far