Guest User

function

a guest
Nov 16th, 2018
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. <?php
  2.  
  3. //koneksi database
  4. $dbhost = 'localhost';
  5. $dbuser = 'root';
  6. $dbpass = '';
  7. $dbname = 'smartphone';
  8.  
  9. $conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
  10.  
  11.  
  12. function nilai($query) {
  13.  
  14. global $conn;
  15.  
  16. $result = mysqli_query($conn, $query);
  17.  
  18. $rows = [];
  19.  
  20. while($row = mysqli_fetch_assoc($result)) {
  21.  
  22. $rows [] = $row;
  23.  
  24. }
  25.  
  26. return $rows;
  27.  
  28.  
  29. }
  30.  
  31.  
  32. function kirim($insert) {
  33.  
  34. global $conn;
  35.  
  36. $brand = htmlspecialchars($insert['brand'], ENT_QUOTES);
  37. $product = htmlspecialchars($insert['product'], ENT_QUOTES);
  38. $date_realise = htmlspecialchars($insert['date_realise'], ENT_QUOTES);
  39. $price = htmlspecialchars($insert['price'], ENT_QUOTES);
  40. $image = htmlspecialchars($insert['image'], ENT_QUOTES);
  41.  
  42. $query = "INSERT INTO android (
  43.  
  44. brand,
  45. product,
  46. date_realise,
  47. price,
  48. image )
  49.  
  50. VALUES (
  51.  
  52. '$brand',
  53. '$product',
  54. '$date_realise',
  55. '$price',
  56. '$image'
  57. )";
  58.  
  59. $result = mysqli_query($conn, $query);
  60.  
  61. }
  62.  
  63.  
  64. function cari($search) {
  65.  
  66. global $conn;
  67.  
  68. $result = mysqli_query($conn, $search);
  69.  
  70. $rows = [];
  71.  
  72. while($row = mysqli_fetch_assoc($result)) :
  73.  
  74. $rows [] = $row;
  75.  
  76. endwhile;
  77.  
  78. return $rows;
  79. }
  80.  
  81.  
  82.  
  83. function hapus($del_id) {
  84.  
  85. global $conn;
  86.  
  87. $delete = "DELETE FROM android WHERE id = '$del_id' ";
  88.  
  89. $result = mysqli_query($conn, $delete);
  90.  
  91. }
  92.  
  93.  
  94. function ubah($update_id) {
  95.  
  96. global $conn;
  97.  
  98. $id = $update_id['id'];
  99. $brand = htmlspecialchars($update_id['brand']);
  100. $product = htmlspecialchars($update_id['product']);
  101. $date_realise = htmlspecialchars($update_id['date_realise']);
  102. $price = htmlspecialchars($update_id['price']);
  103. $image = htmlspecialchars($update_id['image']);
  104.  
  105.  
  106. $update = "UPDATE android SET
  107.  
  108. brand = '$brand',
  109. product = '$product',
  110. date_realise = '$date_realise',
  111. price = '$price',
  112. image = '$image'
  113.  
  114. WHERE id = '$id' ";
  115.  
  116. $result = mysqli_query($conn, $update);
  117.  
  118.  
  119. }
  120.  
  121.  
  122. ?>
Add Comment
Please, Sign In to add comment