MySQL wpdb 更新查询不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15185425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
wpdb update query not working
提问by adnan
I've made an email script that should update as soon as wp_mail has result. For some reason my value won't update. Have I missed something? I am receiving the mail so the wp_mail works.
我制作了一个电子邮件脚本,它应该在 wp_mail 产生结果后立即更新。出于某种原因,我的值不会更新。我错过了什么吗?我收到邮件,所以 wp_mail 工作。
Cheers!
干杯!
$email_result = wp_mail( $to, $subject, $message, $headers );
if( $email_result ){//wp_mail() processed the request successfully
global $wpdb;
$table_name = $wpdb->prefix . "wpsc_coupon_codes";
$coupon_id = $ereminder->ID;
$ereminders = $wpdb->query( $wpdb->prepare("
UPDATE *
FROM $table_name
SET reminder = 1
WHERE ID = $coupon_id
") );
}
回答by Luke Kalyan Brata Sarker
Try This:
尝试这个:
$wpdb->update( $table_name, array( 'reminder' => 1),array('ID'=>$coupon_id));
回答by echo_Me
try this
尝试这个
UPDATE $table_name
SET reminer = 1
WHERE ID = $coupon_id
回答by RajSar
You may change instead of (UPDATE * FROM)
您可以更改而不是 (UPDATE * FROM)
$ereminders = $wpdb->query($wpdb->prepare("UPDATE $table_name SET reminer='1' WHERE ID=$coupon_id"));
and use no break.
并使用不休息。
Thank you.
谢谢你。
回答by Goran Jakovljevic
Example of mine that is working:
我的工作示例:
$result = $wpdb->update(
$wpdb->prefix .'sae_calendar',
array(
'year' => $year,
'quarter' => $quarter,
'start_date' => $start_date,
'end_date' => $end_date,
'reservation_start_date' => $reservation_start_date,
'reservation_end_date' => $reservation_end_date
),
array(
"id" => $id
)
);
回答by ABHISHEK GUPTA
<?php
global $wpdb;
if(isset($_POST['progress'])){
$table=t_test;
$data=array('client_development'=>$_POST['Progress']);
$where=array('p_id'=>$_SESSION['id']);
$format=("%d");
$whereFormat=("%d");
$result4=$wpdb->UPDATE($table,$data,$where,$format,$whereFormat);
}
?>
<form method="post">
<input type="text" name="Progress">
<input type="submit" name="progress" value="Prog%">
</form>
<?php
if(isset($_POST['progress'])){
$table=t_test;
$data=array('client_development'=>$_POST['Progress']);
$where=array('p_id'=>$_SESSION['id']);
$format=("%d");
$whereFormat=("%d");
$result4=$wpdb->UPDATE($table,$data,$where,$format,$whereFormat);
}
?>
<form method="post">
<input type="text" name="Progress">
<input type="submit" name="progress" value="Prog%">
</form>
回答by Cristian
We could use $wpdb->update
, like this:
我们可以$wpdb->update
像这样使用:
global $wpdb;
$table_name = $wpdb->prefix.'your_table_name';
$data_update = array('row_name_1' => $row_data_1 ,'row_name_2' => $row_data_2);
$data_where = array('row_name' => $row_data);
$wpdb->update($table_name , $data_update, $data_where);
回答by Studio3
UPDATE $table_name
SET reminder = 1
WHERE ID = $coupon_id
Also, change:
另外,更改:
$coupon_id = $ereminder->ID;
to
到
$coupon_id = $ereminder->id;