javascript
  • php
  • jquery
  • mysql
  • sql-delete
  • 2015-10-14 187 views 0 likes 
    0

    我的刪除功能不起作用。Javascript刪除不起作用

    這是我的表與刪除按鈕。

    // retrieve table contents 
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ 
    
    extract($row); 
    
    //creating new table row per record 
    echo "<tr>"; 
        echo "<td class='text-align-center'><input type='checkbox' name='item[]' class='checkboxes' value='{$employeeid}' /></td>"; 
        echo "<td>{$name}</td>"; 
        echo "<td>{$title}</td>"; 
        echo "<td>{$phone}</td>"; 
        echo "<td>{$supplier_name}</td>"; 
        echo "<td>{$created}</td>"; 
        echo "<td>"; 
    
         // update record 
         echo "<a href='update_product.php?employeeid={$employeeid}' class='btn btn-info margin-right-1em'>"; 
          echo "<span class='glyphicon glyphicon-edit'></span> Rediger"; 
         echo "</a>"; 
    
         // delete record 
         echo "<a delete-employeeid='{$employeeid}' delete-file='delete_product.php' class='btn btn-danger delete-object'>"; 
          echo "<span class='glyphicon glyphicon-remove'></span> Slet"; 
         echo "</a>"; 
    
        echo "</td>"; 
    echo "</tr>"; 
    } 
    //end table<br> 
    echo "</table>"; 
    

    這是我的刪除功能

    ​​

    我從我修改了很多的教程代碼。
    除刪除功能外,其他所有功能都正常工作。

    PHP代碼

    <?php 
    // check if value was posted 
    if($_POST){ 
    
        // include database and object file 
        include_once 'config/database.php'; 
    
        // delete query 
        $query = "DELETE FROM employeestest WHERE employeeid = ?"; 
        $stmt = $con->prepare($query); 
        $stmt->bindParam(1, $_POST['object_employeeid']); 
    
        if($stmt->execute()){ 
         // redirect to read records page and 
         // tell the user record was deleted 
         echo "Medarbejderen er slettet."; 
        }else{ 
         echo "Medarbejderen kunne ikke slettes."; 
        } 
    } 
    ?> 
    
    +0

    哪裏是你delete_product.php? –

    +2

    您的html中缺少'delete-id'。不知道它是否是複製+粘貼錯誤。 PHP代碼將有助於和文件夾結構。 – Andrew

    +0

    許多缺少的部分真正得到這裏發生了什麼......需要整個代碼人... – Julo0sS

    回答

    0

    也許你只是做語法錯誤

    'delete-id' => 'delete-employeeid' 
    
    0

    變化

    var id = $(this).attr('delete-Id');

    var id = $(this).attr('delete-employeeid');

    而且,更改$.post$.ajax,因爲我已經給

    <script> 
        $(document).on('click', '.delete-object', function(){ 
         var delete_file = $(this).attr('delete-file'); 
         var id = $(this).attr('delete-employeeid'); 
         var q = confirm("Are you sure?"); 
         if (q == true) 
         { 
          $.ajax({url:delete-file,cache:false,success:function(result){ 
           alert('Successfully Deleted'); 
          }}); 
         } 
         return false; 
        }); 
    </script> 
    
    相關問題