【发布时间】:2018-07-19 23:55:26
【问题描述】:
大家早上好
我的脚本有问题,我不知道如何制作功能。我会解释: 我正在使用 Outlook API 我收到我的邮件,将它们发送到我的收件箱表中的 bdd。然后我有一些按钮允许在其他表中发送我的邮件(做/紧急/存档)。 问题是我想在向另一个表发送电子邮件时删除收件箱数据。
我有一个视图文件(我没有把它放进去我认为它没有用) 包含我的 AJAX 请求的文件:
window.onload = function(item){
console.log("********************TEST_INSERT*********************");
for($i = 0; $i <= 2; $i++){
console.log("after for");
console.log($i);
$thisInput = document.getElementsByClassName('from_1')[$i].textContent;
$thisSub = document.getElementsByClassName('subject_1')[$i].textContent;
$thisRecei = document.getElementsByClassName('received_1')[$i].textContent;
$thisPreview = document.getElementsByClassName('bodypreview_1')[$i].textContent;
$thisBody_2 = document.getElementsByClassName('body_2')[$i].textContent;
console.log("*********************");
console.log($thisInput);
console.log($thisSub);
console.log($thisRecei);
console.log($thisPreview);
console.log($thisBody_2);
console.log("*********************");
console.log("**********************");
console.log("******STOCK************");
console.log("**********************");
//var $input = $(item).closest(".emailBody").find(".from_1")[0].innerHTML;
//var $sub = $(item).closest(".emailBody").find(".subject_1")[0].innerHTML;
//var $recei = $(item).closest(".emailBody").find(".received_1 em")[0].innerHTML;
//var $preview= $(item).closest(".emailBody").find(".bodypreview_1 em")[0].innerHTML;
//var $body_2 = $(item).closest(".emailBody").find(".body_2 em")[0].innerHTML;
$.ajax({url: '../../wp-content/plugins/game_plugin/process_general.php',
type: 'POST',
data: {info: 'stock_mail_inbox', input: $thisInput, sub: $thisSub, recei: $thisRecei, preview: $thisPreview, body : $thisBody_2},
success: function() {
console.log("OK");
}
});
};
$.ajax({url: '../../wp-content/plugins/game_plugin/process_general.php',
type: 'POST',
dataType: 'html',
data: {info: 'display_mail'},
success: function(html) {
console.log("OKok");
$('#display_mail').html(html);
}
});
};
function btn_a_faire(item){
console.log("**********************");
console.log("******ajax A FAIRE************");
console.log("**********************");
var $thisInput = $(item).closest(".emailBody").find(".from_1")[0].innerHTML;
var $thisSub = $(item).closest(".emailBody").find(".subject_1")[0].innerHTML;
var $thisRecei = $(item).closest(".emailBody").find(".received_1 em")[0].innerHTML;
var $thisPreview = $(item).closest(".emailBody").find(".bodypreview_1 em")[0].innerHTML;
var $thisBody_2 = $(item).closest(".emailBody").find(".body_2 em")[0].innerHTML;
console.log($thisBody_2);
$.ajax({url: '../../wp-content/plugins/game_plugin/process_general_2.php',
type: 'POST',
data: {info: 'insert_to_db_a_faire', input: $thisInput, sub: $thisSub, recei: $thisRecei, preview: $thisPreview, body : $thisBody_2},
success: function() {
console.log("OK");
}
});
};
function btn_urgent(item){
console.log("**********************");
console.log("******ajax URGENT************");
console.log("**********************");
var $thisInput = $(item).closest(".emailBody").find(".from_1")[0].innerHTML;
var $thisSub = $(item).closest(".emailBody").find(".subject_1")[0].innerHTML;
var $thisRecei = $(item).closest(".emailBody").find(".received_1 em")[0].innerHTML;
var $thisPreview = $(item).closest(".emailBody").find(".bodypreview_1 em")[0].innerHTML;
var $thisBody_2 = $(item).closest(".emailBody").find(".body_2 em")[0].innerHTML;
$.ajax({url: '../../wp-content/plugins/game_plugin/process_general_3.php',
type: 'POST',
data: {info: 'insert_to_db', input: $thisInput, sub: $thisSub, recei: $thisRecei, preview: $thisPreview, body : $thisBody_2},
success: function() {
console.log("OK");
}
});
}
function btn_archive(item){
console.log("**********************");
console.log("******ajax URGENT************");
console.log("**********************");
var $thisInput = $(item).closest(".emailBody").find(".from_1")[0].innerHTML;
var $thisSub = $(item).closest(".emailBody").find(".subject_1")[0].innerHTML;
var $thisRecei = $(item).closest(".emailBody").find(".received_1 em")[0].innerHTML;
var $thisPreview = $(item).closest(".emailBody").find(".bodypreview_1 em")[0].innerHTML;
var $thisBody = $(item).closest(".emailBody").find(".body_2 em")[0].innerHTML;
$.ajax({url: '../../wp-content/plugins/game_plugin/process_general_4.php',
type: 'POST',
data: {info: 'insert_to_db_archive', input: $thisInput, sub: $thisSub, recei: $thisRecei, preview: $thisPreview, body : $thisBody_2},
success: function() {
console.log("OK");
}
});
}
我的 bdd 中有 4 个处理 INSERT 的文件(proccess_general.php/proccess_general_2...):
Process_general.php:
$info = $_POST['info'];
$thisInput= $_POST['input'];
$thisRecei= $_POST['recei'];
$thisSub= $_POST['sub'];
$thisPreview= $_POST['preview'];
$thisBody= $_POST['body'];
stock_mail_inbox($thisInput, $thisSub, $thisRecei, $thisPreview, $thisBody);
function stock_mail_inbox($thisInput, $thisSub, $thisRecei, $thisPreview, $thisBody){
global $wpdb;
$wpdb->insert(
'inbox', //table name
array(
'id' => '',
'from_mail' => $thisInput,
'subject' =>$thisSub,
'recei' => $thisRecei,
'preview' =>$thisPreview,
'body' => $thisBody,
), //columns
array(
'%d',
'%s',
'%s',
'%s',
'%s',
'%s',
)
);
}
proccess_general_2.php:
$info = $_POST['info'];
$thisInput= $_POST['input'];
$thisRecei= $_POST['recei'];
$thisSub= $_POST['sub'];
$thisPreview= $_POST['preview'];
$thisBody= $_POST['body'];
insert_to_db_a_faire($thisInput, $thisSub, $thisRecei, $thisPreview, $thisBody);
function insert_to_db_a_faire($thisInput, $thisSub, $thisRecei, $thisPreview, $thisBody){
global $wpdb;
$wpdb->insert(
'a_faire', //table name
array(
'id' => '',
'from_mail' => $thisInput,
'subject' =>$thisSub,
'recei' => $thisRecei,
'preview' =>$thisPreview,
'body' => $thisBody,
), //columns
array(
'%d',
'%s',
'%s',
'%s',
'%s',
'%s',
)
);
$wpdb->prepare('DELETE FROM `inbox` WHERE recei = $thisRecei');
}
在 proccess_general_2 我添加了一个 DELETE 但它不起作用。当我在 phpmyadmin 中测试我的请求时,它可以工作,但是一旦在我的代码中就没有任何效果。 我希望已经清楚,如有必要,我仍然可以使用。 感谢大家度过美好的一天。
【问题讨论】:
-
检查sql错误/php日志,可能是错误
-
据我所知 wpdb,->prepare 并没有真正执行查询,你需要在准备好之后再做一个->查询
标签: javascript php mysql wordpress sql-delete