2017-04-10 122 views
-5

我选择在WordPress它的工作,但 我在WordPress有问题访问WordPress的功能,我想更新表,但回到问题我不能从一个Ajax PHP呼叫

这是当我想更新错误我表在WordPress: this is the error when i want to update my table in wordpress

+1

人们试图编辑ÿ我们的问题让它变得更好 - 请不要再让它变得更糟。 – Tom

+1

代码在哪里? – ggdx

+0

看起来像你回应全页面内容而不是单行文本。 – Justinas

回答

1
// Insert location of wp-load.php 
require("/var/www/yourdomain.com/htdocs/wp-load.php"); 
// Insert function to get db connection environment 
function db_connect() 
{ 
    $mydb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); 
     return $mydb; 
} 
// Sql Query 
$sql="UPDATE inscription SET ".$_POST["name"]." = '".$_POST["value"]."'WHERE id = '".$_POST["pk"]."'"; 

$result_insert = db_connect()->get_results($sql); 
+0

非常感谢Punit Patel的答案,但仍然是与我同样的问题。 – ab2info

-1

这是我的网页,我有AJAX和jQuery

<?php /* Template Name: fetch presence*/ 
     $today = getdate(); 
     $y = $today['year']; 
     $today = getdate(); 
     $y = $today['year']; 
    ?> 
    <!DOCTYPE html> 
    <html> 
    <head> 
     <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"> 
     <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script> 
     <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> 
     <link href="https://cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.1/bootstrap3-editable/css/bootstrap-editable.css" rel="stylesheet"> 
     <script src="https://cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.1/bootstrap3-editable/js/bootstrap-editable.js"></script> 
    <style> 
    .btn-a{ 
    display: flex; justify-content: center; 
    margin-top: 20px; 
    } 
    .img{ 
     display: flex; justify-content: center; 
    } 
    .btn-group .button { 
     background-color:#f44336; /* Green */ 
     border: none; 
     color: white; 
     padding: 15px 32px; 
     text-align: center; 
     text-decoration: none; 
     display: inline-block; 
     font-size: 16px; 
     cursor: pointer; 
     float: top; 
     box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19); 
    } 
    .btn-group .button:hover { 
     background-color: #3e8e41; 
    } 
    </style> 
    </head> 
    <body> 
    <div class="img"><img src="http://localhost/wordpress/wp-content/uploads/2017/04/calender.png" height="117px"></div> 
    <header class="btn-a"> 
    <div class="btn-group"> 
     <button class="button" Onclick="parent.location='Seminaire1.php'">Seminaire 1</button> 
     <button class="button" Onclick="parent.location='Seminaire2.php'">Seminaire 2</button> 
     <button class="button" Onclick="parent.location='Seminaire3.php'">Seminaire 3</button> 
     <button class="button" Onclick="parent.location='Seminaire4.php'">Seminaire 4</button> 
    </div> 
    </header> 
     <div class="container"> 
     <h1 align="center">Feuille de Présence Seminaire 2: Promotion <?php echo $y;?></h1> 
     </br> 
     <table class="table table-bordered table-striped"> 
     <thead> 
     <tr> 
     <th width="2%" >Id</th> 
      <th width="10%" >Cin</th> 
      <th width="10%">Nom</th> 
      <th width="10%">Prenom</th> 
      <th width="10%">Spécialité</th> 
      <th width="10%">Presnece</th> 
      <th width="10%">Presnece</th> 
      <th width="10%">Presnece</th> 
     </tr> 
     </thead> 
     <tbody id="employee_data"> 
     </tbody> 
     </table> 

    </body> 
    </html> 
    <script type="text/javascript" language="javascript"> 
       $(document).ready(function(){ 

        function fetch_employee_data() 
        { 
        $.ajax({ 
        url:"http://localhost/wordpress/fetch", 
        method:"POST", 
        dataType:"json", 
        success:function(data) 
        { 
         for(var count=0; count<data.length; count++) 
        { 
        var html_data = '<tr><td>'+data[count].id+'</td>'; 
        html_data += '<td data-name="cin" class="cin" data-type="text" data-pk="'+data[count].id+'">'+data[count].cin+'</td>'; 
        html_data += '<td data-name="nom" class="nom" data-type="text" data-pk="'+data[count].id+'">'+data[count].nom+'</td>'; 
        html_data += '<td data-name="prenom" class="prenom" data-type="text" data-pk="'+data[count].id+'">'+data[count].prenom+'</td>'; 
        html_data += '<td data-name="Specialite" class="Specialite" data-type="select" data-pk="'+data[count].id+'">'+data[count].Specialite+'</td>'; 
        html_data += '<td data-name="Presnecea" class="Presnecea" data-type="select" data-pk="'+data[count].id+'">'+data[count].Presnece+'</td>'; 
        html_data += '<td data-name="Presneceb" class="Presneceb" data-type="select" data-pk="'+data[count].id+'">'+data[count].Presnece+'</td>'; 
        html_data += '<td data-name="Presnecec" class="Presnecec" data-type="select" data-pk="'+data[count].id+'">'+data[count].Presnece+'</td>'; 
        $('#employee_data').append(html_data); 
        } 
        } 
        }); 
        } 
     fetch_employee_data(); 
      $('#employee_data').editable({ 
      container: 'body', 
      selector: 'td.cin', 
      url: "http://localhost/wordpress/update", 
      title: 'Cin Employee', 
      type: "POST", 
      //dataType: 'json', 
      validate: function(value){ 
      if($.trim(value) == '') 
      { 
       return 'Ce Champ Est Obligatoire'; 
      } 
      } 
      }); 
     $('#employee_data').editable({ 
      container: 'body', 
      selector: 'td.nom', 
      url: "http://localhost/wordpress/update", 
      title: 'Nom Employee', 
      type: "POST", 
      //dataType: 'json', 
      validate: function(value){ 
      if($.trim(value) == '') 
      { 
       return 'Ce Champ Est Obligatoire'; 
      } 
      } 
      }); 
     $('#employee_data').editable({ 
      container: 'body', 
      selector: 'td.prenom', 
      url: "http://localhost/wordpress/update", 
      title: 'Prenom Employee', 
      type: "POST", 
      //dataType: 'json', 
      validate: function(value){ 
      if($.trim(value) == '') 
      { 
       return 'Ce Champ Est Obligatoire'; 
      } 
      } 
      });  
     $('#employee_data').editable({ 
      container: 'body', 
      selector: 'td.Specialite', 
      url: "http://localhost/wordpress/update", 
      title: 'Specialite', 
      type: "POST", 
      dataType: 'json', 
      source: [{value: "redaction medicale", text: "redaction medicale"}, {value: "epidemologie et recherche clinique", text: "epidemologie et recherche clinique"}], 
      validate: function(value){ 
      if($.trim(value) == '') 
      { 
       return 'Ce Champ Est Obligatoire'; 
      } 
      } 
      }); 
     $('#employee_data').editable({ 
      container: 'body', 
      selector: 'td.Presnecea', 
      url: "http://localhost/wordpress/update", 
      title: 'Presnecea', 
      type: "POST", 
      dataType: 'json', 
      source: [{value: "Non", text: "Non"}, {value: "Oui", text: "Oui"}], 
      validate: function(value){ 
      if($.trim(value) == '') 
      { 
       return 'Ce Champ Est Obligatoire'; 
      } 
      } 
      }); 
     $('#employee_data').editable({ 
      container: 'body', 
      selector: 'td.Presneceb', 
      url: "http://localhost/wordpress/update", 
      title: 'Presneceb', 
      type: "POST", 
      dataType: 'json', 
      source: [{value: "Non", text: "Non"}, {value: "Oui", text: "Oui"}], 
      validate: function(value){ 
      if($.trim(value) == '') 
      { 
       return 'Ce Champ Est Obligatoire'; 
      } 
      } 
      }); 
     $('#employee_data').editable({ 
      container: 'body', 
      selector: 'td.Presnecec', 
      url: "http://localhost/wordpress/update", 
      title: 'Presnecec', 
      type: "POST", 
      dataType: 'json', 
      source: [{value: "Non", text: "Non"}, {value: "Oui", text: "Oui"}], 
      validate: function(value){ 
      if($.trim(value) == '') 
      { 
       return 'Ce Champ Est Obligatoire'; 
      } 
      } 
      });    
      }); 


    </script> 
+0

这里一样的东西。更新您的问题以添加相关代码,如果不是答案,请不要添加答案。请花一些时间阅读[如何创建最小,完整和可验证示例](https://stackoverflow.com/help/mcve)。 –