Advertisement
Guest User

Untitled

a guest
May 25th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. <?php
  2. session_start();
  3. error_reporting(0);
  4. include "inc/koneksi.php";
  5. include "inc/tanggal.php";
  6.  
  7. $input=$_GET['input'];
  8. $sid = session_id();
  9. $inputform=$_GET['inputform'];
  10.  
  11. if($input=='add'){
  12.  
  13. $sql = mysql_query("SELECT id_product FROM keranjang WHERE id_product='$_GET[id]' AND id_session='$sid'");
  14. $num = mysql_num_rows($sql);
  15. if ($num==0){
  16. mysql_query("INSERT INTO keranjang(id_product,
  17. id_session,
  18. tgl_keranjang,
  19. qty)
  20. VALUES ('$_GET[id]',
  21. '$sid',
  22. '$tgl_sekarang',
  23. '1')");
  24. }
  25. else {
  26. mysql_query("UPDATE keranjang SET qty = qty + 1 WHERE id_session = '$sid' AND id_product='$_GET[id]'");
  27. }
  28. deletecart();
  29. echo "<script>window.alert('Barang Sudah di Tambah Ke Keranjang Anda');
  30. window.location=('../cart.php')</script>";
  31. }
  32. else if ($input=='kurang'){
  33. mysql_query("UPDATE keranjang SET qty = qty - 1 WHERE id_session = '$sid' AND id_product='$_GET[id]'");
  34. header('location:../cart.php');
  35. }
  36. else if ($input=='tambah'){
  37. mysql_query("UPDATE keranjang SET qty = qty + 1 WHERE id_session = '$sid' AND id_product='$_GET[id]'");
  38. header('location:../cart.php');
  39. }
  40. else if ($input=='delete'){
  41. mysql_query("DELETE FROM keranjang WHERE id_keranjang='$_GET[id]'");
  42. header('location:../cart.php');
  43. }
  44.  
  45. else if ($input=='inputform'){
  46. function cart_content(){
  47. $ct_content = array();
  48. $sid = session_id();
  49. $sql = mysql_query("SELECT * FROM keranjang WHERE id_session='$sid'");
  50.  
  51. while ($r=mysql_fetch_array($sql)) {
  52. $ct_content[] = $r;
  53. }
  54. return $ct_content;
  55. }
  56. $ct_content = cart_content();
  57. $jml = count($ct_content);
  58. $now = date("Ymd");
  59. for($i=0; $i<$jml; $i++){
  60. mysql_query("INSERT INTO order_product(name,
  61. email,
  62. phone,
  63. address,
  64. id_product,
  65. jumlah,
  66. total,
  67. tanggal,
  68. id_pemesan)
  69. VALUES ('$_POST[name]',
  70. '$_POST[email]',
  71. '$_POST[telp]',
  72. '$_POST[address]',
  73. {$ct_content[$i]['id_product']},
  74. {$ct_content[$i]['qty']},
  75. '$_POST[total]',
  76. '$now',
  77. '$sid')");
  78.  
  79. mysql_query("MASUKIN SCRIPT INSERT YG KEDUA DISINI");
  80. }
  81. for($i=0; $i<$jml; $i++){
  82. mysql_query("DELETE FROM keranjang WHERE id_keranjang = {$ct_content[$i]['id_keranjang']}");
  83. }
  84. echo "<script>window.alert('Terima Kasih Pesanan Anda Sedang Kami Proses');
  85. window.location=('../home.php')</script>";
  86. }
  87.  
  88.  
  89. function deletecart(){
  90. $del = date('Y-m-d', mktime(0,0,0, date('m'), date('d') - 1, date('Y')));
  91. mysql_query("DELETE FROM keranjang WHERE tgl_keranjang < '$del'");
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement