Reputation: 97
Good morning, everyone,
I have a problem with my script I can't figure out how to make a feature. I'll explain: I'm using the outlook API I get my mails, send them to my bdd in an inbox table. I then have some buttons that allow to send my mails in other table (to do/ Urgent/Archive). The problem is that I want to delete the inbox data when I send an email to another table.
I have a view file (I don't put it in I don't think it's useful) A file with my AJAX request:
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");
}
});
}
And I have 4 files that process INSERTs in my bdd (proccess_general. php/proccess_general_2...):
Proccess_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');
}
In proccess_general_2 I added a DELETE but it doesn't work. When I test my request in phpmyadmin it works but once in my code nothing works. I hope to have been clear, I remain available if necessary. Thank you all for a great day.
Upvotes: 3
Views: 100
Reputation: 3234
You should have something like execute( )
after preparing. Try this (or find the equivalent, according to what tools you use)
$wpdb->prepare('DELETE FROM `inbox` WHERE recei = $thisRecei');
$wpdb->execute();
Upvotes: 1