我有一个表单,在通过ajax提交表单时更新数据库表中的列。一切都很好,数据库表列可以获取信息,但一旦刷新浏览器,信息就会从数据库中删除。
如果meta\\u值不存在,但meta\\u值也在提交表单时创建的数据库中,则PHP将执行数据库更新。
我希望信息保留在数据库中,直到或除非meta\\u值被删除或不存在。
任何见解都将不胜感激。
PHP
add_action(\'wp_ajax_hide_this\', \'hide_this_by_id\');
add_action(\'wp_ajax_nopriv_hide_this\', \'hide_this_by_id\');
function hide_this_by_id()
{
global $wpdb;
$wpdbPrefix = $wpdb->prefix . \'swpm_members_tbl\';
$postdVlaue2 = $_POST[\'hidebtn2\'];
$this_user = $_POST[\'thisuser\'];
$this_num = $_POST[\'thisnum\'];
if (is_user_logged_in()) {
$member_id = SwpmMemberUtils::get_logged_in_members_id();
$query = "SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl WHERE member_id = %d";
$userData = $wpdb->get_row($wpdb->prepare($query, $member_id));
$membership_levels = $userData->membership_level;
$labelID4 = $membership_levels;
$insertdisUr = $wpdb->update( $wpdbPrefix, array( \'this_user\' => $this_user), array( \'member_id\' => $member_id));
$insertdisId = $wpdb->update( $wpdbPrefix, array( \'this_id\' => $this_num), array( \'member_id\' => $member_id));
} else {
$not_loggedin = 1;
}
if ($labelID4 == 10 ) {
$userlvlMeta2 = 1;
$alredyclick3 = get_user_meta($member_id, \'hidden-info\', true);
if (empty($alredyclick3) && $postdVlaue2 == 1) {
$insertdisUr;
$insertdisId;
$alredyclick3 = 1;
}
}
$return4 = array(
\'hIdethis2\' => $this_hide2,
\'userlvlMeta2\' => $userlvlMeta2,
\'userlvlNolog\' => $not_loggedin,
);
echo json_encode($return4);
die();
}
jQuery
function doAjaxRequest4(hidebtn2,getthisInfo,getthisInfo2) {
jQuery.ajax({
url: ajax_sib_front_object.ajax_url,
data: {
\'action\': \'hide_this\',
\'thisuser\': getthisInfo,
\'thisnum\': getthisInfo2,
\'hidebtn2\': hidebtn2
},
dataType: \'JSON\',
type: "post",
success: function (data) {
console.log(data.test);
var input = jQuery(\'.thisuser > input\');
var input2 = jQuery(\'.thisnumber > input\');
var is_name = input.length > 3;
var is_name2 = input2.length > 3;
if (!data.hIdethis2 == 1 && data.userlvlMeta2 == 1) {
jQuery("#this_col_1").addClass("enable_this");
} else if (data.hIdedisc2 == 1 && is_name && is_name2 ) {
jQuery("#this_col_1").removeClass("enable_this");
jQuery("#this_col_2").addClass("enable_this");
}
}
});
}
函数调用方
if ($(\'body\').is(\'.page-id-9999\') || $(\'body\').is(\'.page-id-1111\')) {
var thisbtn = document.querySelector(\'#this_verf_form > div > .wpcf7\');
thisbtn.addEventListener(\'wpcf7submit\', function (event) {
var status = event.detail.status;
console.log(status);
if (status === \'mail_sent\') {
jQuery(\'#this_submtID\').val("Submitted");
}
setTimeout(function () {
doAjaxRequest4(1,getthisInfo,getthisInfo2);
}, 3500);
}, false);
}