Advertisement
Guest User

Untitled

a guest
Apr 13th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. program index.php
  2. <!doctype html>
  3. <html lang="en">
  4. <head>
  5. <title>Menghapus Data Tanpa Merefresh Halaman dengan Ajax</title>
  6. <meta content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" name="viewport"/>
  7. <meta content="Aguzrybudy" name="author"/>
  8. <link href="css/bootstrap.css" rel="stylesheet">
  9. <script src="js/jquery.min.js"></script>
  10. <script src="js/bootstrap.min.js"></script>
  11. </head>
  12. <body>
  13.  
  14. <div class="container">
  15. <h2>
  16. Menghapus Data Tanpa Merefresh Halaman dengan Ajax</h2>
  17.  
  18. <p>
  19. <a href="#" class="btn btn-success" data-target="#ModelAdd" data-toggle="model">Add Data</a></p>
  20. <table id="mytable" class="table table-bordered"><thead> <th>id</th> <th>Name</th> <th>Alamat</th> <th>Jabatan</th> </thead> <?php
  21. include "koneksi.php";
  22. $no = 0;
  23. $model=mysqli_query($kon,"SELECT * FROM model");
  24. while($r=mysqli_fetch_array($model)){
  25. $no++;
  26.  
  27. ?>
  28. <tr> <td><?php echo $no; ?></td> <td><?php echo $r['model_nama']; ?></td> <td><?php echo $r['description']; ?></td> <td>
  29. <a href="#" class='open_model' id='<?php echo $r['model_id']; ?>'>Edit</a>
  30. <a href="#" onclick="confirm_modal('proses_delete.php?&model_id=<?php echo $r['model_id']; ?>');">Delete</a>
  31. </td> </tr>
  32. <?php } ?> </table>
  33. </div>
  34. <script type="text/javascript">
  35. $(document).ready(function () {
  36. $(".open_modal").click(function(e) {
  37. var m = $(this).attr("id");
  38. $.ajax({
  39. url: "modal_edit.php",
  40. type: "GET",
  41. data : {model_id: m,},
  42. success: function (ajaxData){
  43. $("#ModalEdit").html(ajaxData);
  44. $("#ModalEdit").modal('show',{backdrop: 'true'});
  45. }
  46. });
  47. });
  48. });
  49. </script>
  50.  
  51. <script type="text/javascript">
  52. function confirm_modal(delete_url)
  53. {
  54. $('#modal_delete').modal('show', {backdrop: 'static'});
  55. document.getElementById('delete_link').setAttribute('href' , delete_url);
  56. }
  57. </script>
  58.  
  59. </body>
  60. </html>
  61.  
  62. koneksi.php
  63. <?php
  64. error_reporting(E_ALL ^ E_DEPRECATED);
  65. $host = "localhost";
  66. $user = "root";
  67. $pass = "";
  68. $dbName = "teknologiweb2";
  69.  
  70. $kon = mysqli_connect($host, $user, $pass);
  71. if (!$kon)
  72. die("Gagal Koneksi...");
  73.  
  74. $hasil = mysqli_select_db($kon, $dbName);
  75. if (!$hasil) {
  76. $hasil = mysqli_query($kon, "CREATE DATABASE $dbName");
  77. if (!$hasil)
  78. die("Gagal Buat Database");
  79. else
  80. $hasil = mysqli_select_db($kon, $dbName);
  81. if (!$hasil) die ("Gagal Konek Database");
  82. }
  83.  
  84. $sqlTabelModel = "create table if not exists model (
  85. model_id int(11) auto_increment not null primary key,
  86. model_nama varchar(10) not null,
  87. description text,
  88. date timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  89. KEY(model_id))" ;
  90. mysqli_query ($kon, $sqlTabelModel) or die("Gagal Buat Tabel Model");
  91.  
  92.  
  93. ?>
  94.  
  95. delete.php
  96. <?php
  97. include "koneksi.php";
  98. $model_id=$_GET['model_id'];
  99. $model=mysqli_query($kon,"Delete FROM model WHERE model_id='$model_id'");
  100. header('location:index.php');
  101. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement