2014-12-05 33 views
-2

我在刪除桌面上的某個記錄時遇到問題。我目前所做的是爲刪除和編輯創建兩個表單。出於某種原因,我無法獲得已刪除的所需ID。刪除桌面上的記錄

我嘗試回顯從該窗體傳遞的id的值。和通過的ID是13.

所以基本上我做了一個循環的行。我只是有問題從某一行獲取ID。

這裏是我的表的截圖。

http://prntscr.com/5df5xf

這裏就是我使用的形式

customer.php

<div class="box-body table-responsive"> 
            <form id='edit' action="functions/edit.php" method="post"></form> 
            <form id='delete' action="functions/delete.php" method="post"></form> 
            <table id="example1" class="table table-bordered table-striped"> 
             <thead> 
              <tr> 
               <th>Actions</th> 
               <th>ID</th> 
               <th>User</th> 
               <th>Contact Number</th> 
               <th>Date Registered</th> 
               <th>Email</th> 
               <th>Organization</th> 
               <th>Address</th> 


              </tr> 
             </thead> 
             <tbody> 


             <?php 

             $Query = mysqli_query($conn, "SELECT * FROM customer"); 

              while($row = mysqli_fetch_array($Query)){ 


              echo "<tr>"; 
              echo "<td><div class='btn-group'> 

                <button type='button' class='btn btn-info dropdown-toggle' data-toggle='dropdown'>Action 
                 <span class='caret'></span> 
                 <span class='sr-only'>Toggle Dropdown</span> 
                </button> 

                <ul class='dropdown-menu' role='menu'> 
                 <li><button form='edit' class='btn' type='submit' name='edit' style='width: 100%;background-color: white;'>Edit</button></li> 
                 <li><button form='delete' class='btn' type='submit' name='delete' style='width: 100%;background-color: white;'>Delete</button></li> 
                </ul> 
                </div> 
                </td>"; 


              echo "<td>". "<input form='delete' type='hidden' name='id' value='" . $row['id'] . "'> " . $row['id'] . "</td>"; 
              echo "<td>". $row['firstname'] . " " . $row['lastname'] . "</td>"; 
              echo "<td>". $row['contact'] . "</td>"; 
              echo "<td>". $row['date_reg'] . "</td>"; 
              echo "<td><span class='label label-success'>" . $row['email'] . "</span></td>"; 
              echo "<td>". $row['organization'] . "</td>"; 
              echo "<td>". $row['address'] . "</td></tr>"; 

              } 
              ?> 

             </tbody> 
             <tfoot> 
              <tr> 
               <th>Actions</th> 
               <th>ID</th> 
               <th>User</th> 
               <th>Contact Number</th> 
               <th>Date Registered</th> 
               <th>Email</th> 
               <th>Organization</th> 
               <th>Address</th> 


              </tr> 
             </tfoot> 
            </table> 


          </div> 

這裏是我的delete.php看起來像

<?php 

    include('config.php'); 

    $deleteID = $_POST['id']; 


    //----- Check if user to be deleted is the user in session -----// 

    echo $deleteID; 
    // $deleteSQL = mysqli_query($conn, "delete from customer where id = '$deleteID'"); 


    echo "<script type='text/javascript'>alert('Deleted succesfuly');</script>"; 
    //header('Refresh: 0; url=../customers.php'); 

    // 
?> 
+1

分享您的代碼 – 2014-12-05 11:01:01

+0

請給我們展示一些代碼。我們無法憑空發明答案。 – Jerodev 2014-12-05 11:01:14

+0

更新了帖子。抱歉! – 2014-12-05 11:06:43

回答

0

你delete.php應該是這樣的:

<?php 
    include('config.php'); 
    $deleteID = $_POST['id']; 
    // Create connection 
    $conn = new mysqli($servername, $username, $password, $dbname); 
    // Check connection 
    if ($conn->connect_error) { 
     die("Connection failed: " . $conn->connect_error); 
    } 
    $deleteSQL = mysqli_query($conn, "delete from customer where id = '$deleteID'"); 
    if ($conn->query($sql) === TRUE) { 
     echo "<script type='text/javascript'>alert('Deleted succesfuly');</script>"; 
    //header('Refresh: 0; url=../customers.php'); 
    } else { 
     echo "Error: " . $sql . "<br>" . $conn->error; 
    } 

    $conn->close(); 
    ?> 

現在,如果$servername, $username, $password, $dbname在您的config.php正確指定這會工作。

非常差的編碼從你身邊。

+0

謝謝!是的,我知道,我只是試圖確保在改進我的代碼之前將正確的ID傳遞給delete.php。 – 2014-12-06 02:42:54

+0

那我的答案呢?它看起來對你來說是錯誤的嗎? – 2014-12-08 04:17:26