2014-12-05 3 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

코드를 공유하십시오. –

+0

일부 코드를 알려주십시오. 우리는 얇은 공기에서 응답을 발명 할 수 없습니다. – Jerodev

+0

이 (가) 게시물을 업데이트했습니다. 죄송합니다! –

답변

0

귀하의 delete.php 같은 다음과 같이되어야합니다. $servername, $username, $password, $dbnameconfig.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(); 
    ?> 

지금이 작동합니다.

매우 편협한 코딩.

+0

감사합니다! 잘 모르겠지만 코드를 개선하기 전에 올바른 ID가 delete.php로 전달되는지 확인하려고했습니다. –

+0

그럼 내 대답은 어떨까요? 너에게 잘못된 것 같니? –