[英]WordPress: How to update data in database using PHP with MySQL?
I am using core PHP to make WordPress custom page template for my website, but when I am updating user id, it was not updating the user id. 我正在使用核心PHP为我的网站制作WordPress自定义页面模板,但是当我更新用户ID时,它并没有更新用户ID。
Suppose I have a user in database and when the user pay amount using PayPal, make that user id 1. By default its id is 0. 假设我有一个用户在数据库中,并且当用户使用PayPal支付金额时,将其设为1。默认情况下,其ID为0。
$wpdb->query( $wpdb->prepare( "UPDATE user_register SET pay_status = '$pay_status' WHERE wp_user_id = $current_user" ) );
I want to make that user status to 1 when paid. 我想在付款时将该用户状态设置为1。
Your code should work. 您的代码应该可以工作。 But without knowing the full source code we don't know why it doesn't work. 但是,在不了解完整源代码的情况下,我们不知道为什么它不起作用。
Although you can do update $wpdb->query
, $wpdb does have a better way to update a row. 尽管您可以更新$wpdb->query
,但是$ wpdb确实有更好的更新行的方法。 Use $wpdb->update
instead. 请改用$wpdb->update
。
if($user_is_paying){
global $wpdb;
$table = 'user_register';
$data = array('pay_status'=>$pay_status);
$where = array('wp_user_id'=>$current_user);
$wpdb->update( $table, $data, $where);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.