我正在使用wordpress,需要用jQuery ajax更新表格数据,我有以下代码,可以成功发布数据。
jQuery('#update-<?php echo $row->id; ?>').live('click', function (){
var myname = jQuery('input[name="name_two"]').val();
var mystep = jQuery('#step<?php echo $row->id; ?> option:selected').val();
jQuery.ajax({
type: "POST",
url: "/wp-content/plugins/gates/updateGateData.php",
data: {name_two:myname, step_two:mystep},
success: function(data) {
alert('Data updated');
},
});
});现在,我的问题在于如何在updateGateOption.php文件中放入什么内容以post来更新数据库。
感谢大家的回复!所以我现在有了这个:
$name = $_POST['name_two'];
$step = $_POST['step_two'];
global $wpdb;
$wpdb->update(
'gate_options',
array(
'step' => $step,
'name' => $name,
'image_path' => 'new-img-path',
'option' => strtolower($name),
'value' => strtolower($name),
)
);但是值没有更新,而且我看不到任何错误。
发布于 2014-04-24 17:44:34
在updateGateOption.php中尝试以下代码:
$name = $_POST['name_two'];
$step = $_POST['step_two'];现在运行您的查询,
if(mysql_query("UPDATE tablename SET field1= $name, field2=step WHERE 1=1 AND YOUR_CONDITION")){
echo "Data updated successfully";
}else{
echo "Something went wrong";
}https://stackoverflow.com/questions/23265223
复制相似问题