Advertisement
morganisa

delete

Jul 27th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. asumsi punya tabel db dengan nama daftar dan kolom no_pendaftaran dan nama
  2.  
  3. save file dengan nama index.php
  4.  
  5. <?php
  6. include("../dbkoneksi.php"); // menghubungkan ke file koneksi.php agar terhubung dengan database
  7. $link = koneksi_db();
  8. $q = mysql_query("Select * from daftar") or die (mysql_error();
  9.  while ($data = mysql_fetch_array($q)) {
  10. ?>
  11. <table>
  12. <tr>
  13. <td> No_pendaftara </td>
  14. <td> Nama </td>
  15. <td> Aksi </td>
  16. </tr>
  17. <tr>
  18. <td><?php echo $data['no_pendaftaran']; ?> </td>
  19. <td><?php echo $data['nama']; ?> </td>
  20. <td><a href="hapus.php?no_pendaftaran=<?php echo $data['no_pendaftaran']; ?> </td>
  21. </tr>
  22. </table>
  23. <?php
  24. }
  25. ?>
  26.  
  27.  
  28. kemudain buat file hapus.php isi dengan script
  29.  
  30. <?php
  31. include("../dbkoneksi.php"); // menghubungkan ke file koneksi.php agar terhubung dengan database
  32. $link = koneksi_db();
  33. $no_pendaftaran = $_GET['no_pendaftaran'];
  34. $query_hapus = mysql_query("DELETE FROM daftar WHERE no_pendaftaran = '$no_pendaftaran'");
  35. if ($query_hapus){
  36. ?><script>document.location.href="sukses.php"</script><?php
  37. }else{//jika gagal menghapus
  38. echo "Gagal : ".mysql_error();
  39. }
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement