【问题标题】:SQL request DuplicatedSQL 请求重复
【发布时间】:2018-07-15 04:39:55
【问题描述】:

大家早上好 我的脚本有问题。 我使用 Outlook API,我的目标是将我的电子邮件存储在我的数据库中。 到目前为止,一切都很好。然后我希望能够将我的电子邮件移动到其他表格。我希望能够单击一个按钮将我的电子邮件存储在所需的表中。 我设法为一张桌子做到了。插入进展顺利。当我尝试添加表格时,问题就来了。 当我在我的第一个表中插入时,它会自动将邮件复制到另一个表中。 我不明白,我必须忘记一些事情。

我的脚本:

我查看的文件:

<div id="onglets" class="row justify-content-around">
                            
<button type="submit"  class="btn btn-primary col-2" onclick="show_menu('inbox')" > <a href="#inbox">Inbox </a></button>
<button type="submit" class="btn btn-primary col-2" onclick="show_menu('etat')" >Facebook</button>
<button type="submit" class="btn btn-primary col-2" onclick="show_menu('zone')" > Fun </button>
<button type="submit" class="btn btn-primary col-2" onclick="show_menu('chat'),btn_display_urgent()" > Urgent </button>
<button type="submit" class="btn btn-primary col-2" onclick="show_menu('coffre'),btn_display_a_faire()" > A faire </button>
<button type="submit" class="btn btn-primary col-2" onclick="show_menu('rapport')" > Archive </button>
</div>
   




<script id="msg-list-template">
      
<div class="row">
 <div class="col-lg-12 option_test"> 
    {{#each messages}}
         <div class="emailBody">
         
        <h3 id="msg-from" class="list-group-item-heading from_1">{{this.from.emailAddress.name}}</h3>
            
        <h4 id="msg-subject" class="test list-group-item-heading subject_1">{{this.subject}}</h4><button type="submit"  class="btn btn-primary btn-sm col-1" onclick="btn_urgent(this)" >urgent</button><button type="submit"  class="btn btn-primary btn-sm col-1" onclick="btn_a_faire(this)" >A faire</button>
            
        <p id="msg-received" class="list-group-item-heading text-muted received_1"><em>Received: {{formatDate this.receivedDateTime}}</em></p>

        <div id="post1" class="azerty">
            <p id="msg-bodyPreview" class="list-group-item-text text-muted azerty bodypreview_1"><em>{{this.bodyPreview}}</em></p>
            <div class="demasquer">
                    <p id="msg-uniqueBody" class="body_1"><em>{{{this.uniqueBody.content}}}</em></p>;
                        <p id="msg-uniqueBody" class="body_2 hidden"><em>{{this.uniqueBody.content}}</em></p>;
                        
            </div>
        </div> 
 </div>
          }
  }  
    {{/each}}
    </div>
  </div> 
  </script>

我的 AJAX 请求的文件:

  window.onload = function(){
      
      console.log("********************TEST_INSERT*********************");
   
   
      for($i = 0; $i <= 4; $i++){
          console.log("after for");
          console.log($i);
   $input = document.getElementsByClassName('from_1')[$i].textContent;
   $sub = document.getElementsByClassName('subject_1')[$i].textContent;
   $recei = document.getElementsByClassName('received_1')[$i].textContent;
   $preview = document.getElementsByClassName('bodypreview_1')[$i].textContent;
   $body_2 = document.getElementsByClassName('body_2')[$i].textContent;
    console.log("*********************");
    console.log($input);
    console.log($sub);
    console.log($recei);
    console.log($preview);
    console.log($body_2);
    console.log("*********************");
    
    
}};                   

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 = $(item).closest(".emailBody").find(".body_2 em")[0].innerHTML;
$.ajax({url: '../../wp-content/plugins/game_plugin/process_general_2.php',
    type: 'POST',
    data: {info: 'a_faire', input: $thisInput, sub: $thisSub, recei: $thisRecei, preview: $thisPreview, body : $thisBody},
    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 = $(item).closest(".emailBody").find(".body_2 em")[0].innerHTML;
$.ajax({url: '../../wp-content/plugins/game_plugin/process_general.php',
    type: 'POST',
    data: {info: 'insert_to_db', input: $thisInput, sub: $thisSub, recei: $thisRecei, preview: $thisPreview, body : $thisBody},
    success: function() {
        console.log("OK");
    }
});
}

以及我发出 SQL 请求的文件:

$info = $_POST['info'];
$thisInput= $_POST['input'];
$thisRecei= $_POST['recei'];
$thisSub= $_POST['sub'];
$thisPreview= $_POST['preview'];
$thisBody= $_POST['body'];
// Then call the function
insert_to_db($thisInput, $thisSub, $thisRecei, $thisPreview, $thisBody);

 function insert_to_db($thisInput, $thisSub, $thisRecei, $thisPreview, $thisBody){
     
global $wpdb;

         $wpdb->insert(
                    'test_insert', //table name
                    array(
                'id' => '',
                'from_mail' => $thisInput,
                'subject'  =>$thisSub,
                'recei' => $thisRecei,
                'preview' =>$thisPreview,
                'body'  => $thisBody,
                
                    ), //columns
                    array(
                '%d',
                '%s',
                '%s',
                '%s',
                '%s',
                '%s',
                    )
            );

      
  }
 

 a_faire($thisInput, $thisSub, $thisRecei, $thisPreview, $thisBody);
  function a_faire($thisInput, $thisSub, $thisRecei, $thisPreview, $thisBody){

  
 
     
global $wpdb;

         $wpdb->insert(
                    'a_faire', //table name
                    array(
                'id_1' => '',
                'from_mail' => $thisInput,
                'subject'  =>$thisSub,
                'recei' => $thisRecei,
                'preview' =>$thisPreview,
                'body'  => $thisBody,
                
                    ), //columns
                    array(
                '%d',
                '%s',
                '%s',
                '%s',
                '%s',
                '%s',
                    )
            );

     
  }

当我点击紧急按钮时,一切顺利,插入并运行良好。 当我单击 a_do 按钮时,它会在右表中很好地插入,但它也会在紧急表中插入。 我想我缺乏经验不是原因,我尝试了很多东西但没有任何效果。如果有人能建议我解决我的问题,我将不胜感激。

【问题讨论】:

  • ID 必须是唯一的

标签: javascript php sql wordpress


【解决方案1】:

我发现问题出在哪里。错误来自我调用函数的方式......

【讨论】:

    猜你喜欢
    • 2021-06-12
    • 2020-04-30
    • 1970-01-01
    • 2018-08-14
    • 2015-03-01
    • 2019-10-15
    • 1970-01-01
    • 2015-10-14
    • 1970-01-01
    相关资源
    最近更新 更多