2013-07-14 2 views
0

나는 테이블을 만들고있어, 각 행은 행을 삭제하기로되어있는 버튼 삭제가 있습니다. 그러나 이제 삭제를 클릭하면 "아무 일도 일어나지 않습니다."페이지를 새로 고쳐 결과를 확인해야합니다. 도와주세요.PHP 삭제 MySQL의 행 <table>

내 코드의 index.php

<body> 

    <?php include "include/connect.php"; ?> 

    <table> 
     <tr> 
      <th>ID</th> 
      <th>First Name</th> 
      <th>Last Name</th> 
      <th>Proffesion</th> 
      <th>Rank</th> 
      <th>Options</th> 
      <th>&nbsp;</th> 
     </tr> 
     <tr> 
      <form action="add.php" method="post"> 
       <td><input type="text" name="id" disabled size="5"></td> 
       <td><input type="text" name="fname"></td> 
       <td><input type="text" name="lname"></td> 
       <td><input type="text" name="prof"></td> 
       <td><input type="text" name="rank" size="5"></td> 
       <td><input type="submit" value="add" name="watta"></td> 
       <td>&nbsp;</td> 
      </form> 
     </tr> 

     <?php 
      $query = "SELECT * FROM staff"; 
      $vysledek = mysqli_query($link, $query); 

      while ($udaj = mysqli_fetch_array($vysledek)): 

       if($udaj[4]==0){ 
        echo "<tr class='zero'>"; 
       } else { 
        echo "<tr>";  
       } 



       echo "<td>" . $udaj[0] . "</td>"; 
       echo "<td>" . $udaj[1] . "</td>"; 
       echo "<td>" . $udaj[2] . "</td>"; 
       echo "<td>" . $udaj[3] . "</td>"; 
       echo "<td>" . $udaj[4] . "</td>"; 
       echo "<td class='btn'><a href=''>"; 

       ?> 
       <form action="delete.php" method="get"> 
        <input name="id" type="hidden" value="<?php echo $udaj[0]; ?>"> 
        <input name="what" type="submit" value="DELETE"> 
       </form> 

       <?php 
       echo "</a></td>"; 
       echo "<td class='btn'><a href=''>edit</a></td>"; 

       echo "</tr>"; 

      endwhile; 


     ?> 

    </table> 

</body> 

delete.php

<?php 

include "include/connect.php"; 

$toId = ($_GET["id"]); 

$queryy = "DELETE FROM staff WHERE id=$toId"; 
$vysledek = mysqli_query($link, $queryy); 

header('Location: http://www.w3dominik.com/x/phptest/'); 

connect.php

<?php 

include "config.php"; 

$link = mysqli_connect(SQL_HOST, SQL_USERNAME, SQL_PASSWORD, SQL_DBNAME); 
mysqli_set_charset($link, "utf8"); 

if (mysqli_connect_errno()) { 
printf("Connect failed: %s\n", mysqli_connect_error()); 
exit(); 
} 

라이브 데모 connect.php에서 http://www.w3dominik.com/x/phptest/

+0

당신은 delete.php 파일의 데이터베이스에 연결되어 있습니까? –

+1

두 개의 탭/창으로 페이지를 열고 첫 번째 탭에서 행을 삭제하고 해당 탭을 새로 고치면 두 번째 탭에서 삭제 (ON THAT ROW)를 누르면 작동합니다. 즉, 더 많은 코드를 볼 필요가 있습니다 ... 모든'index.php'와'delete.php'를 복사 할 수 있습니까? (그리고 아마 당신의 세부 사항을 제거하는'connect.php') – Steven

+0

이것에 대해 AJAX를 사용해야합니다. [참고] {http://openenergymonitor.org/emon/node/107} –

답변

0

봐에서와 수호하다 다시 출력이 없습니다. header()은 앞에 공백이나 빈 줄이 있으면 작동하지 않습니다. 아주 쉽게 빈 문자를 실수로 넣을 수 있습니다. http://php.net/manual/en/function.header.php

+0

이제 전체 index.php와 connect.php를 추가했습니다. 지금은 어때? – user1505027

+0

문서에 다음과 같이 기록되어 있습니다. '실제 HTML 태그, 파일의 빈 줄 또는 PHP로 실제 출력을 보내기 전에 header()를 호출해야합니다. include, require, 함수 또는 다른 파일 액세스 함수를 사용하여 코드를 읽고 header()가 호출되기 전에 공백이나 빈 줄이 출력되는 것은 매우 일반적인 오류입니다. ' 파일에 빈 줄이 많이 있지만 문제를 일으키는 지 알기 어렵습니다. 나는 가능한 한 많이 인라인 할 것이다. ('include'가 없다면) 문제가 생길 수 있는지 알아보기 위해 – edtheprogrammerguy

+0

이것은 잘못된 것이다. 양식이 다른 페이지로 전송 된 다음 다시 리다이렉션됩니다.'header' 리다이렉트가 작동하지 않으면'headers already sented'라는 메시지가 던져져 오류가 발생하고 다시 양식 페이지로 리디렉션되지 않습니다. – Steven