Guest User

Untitled

a guest
May 11th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(E_ALL);
  4. ini_set('display_errors', 1);
  5.  
  6. $servername = 'localhost';
  7. $username = 'trackuser1';
  8. $password = 'trackSHIVA';
  9. $dbname = 'tracksmmdb';
  10. $coupon_table = 'coupon';
  11. $id_table = 'ident';
  12.  
  13. function format_spec( $string, $separator = '-' )
  14. {
  15. return strtolower(preg_replace('/[^a-zA-Z0-9]/', $separator, $string));
  16. }
  17.  
  18.  
  19.  
  20. $conn = mysqli_connect($servername,$username,$password)
  21. or die ('MySQL Not found // Could Not Connect.');
  22.  
  23.  
  24.  
  25. mysqli_select_db($conn,"$dbname") or die ("No Database found.");
  26.  
  27.  
  28.  
  29. if ( isset($_GET['id']) ){
  30.  
  31. $id = format_spec($_GET['id']);
  32.  
  33. //$sql = "SELECT 1 FROM ident WHERE id = $id";
  34.  
  35. //$result = mysqli_query($conn,$sql);
  36. //$str_res = mysqli_fetch_row($result);
  37.  
  38. //if ($str_res[0]!='1'){
  39. // die ('BAD ID');
  40. //}
  41.  
  42.  
  43. if ($id=='')
  44. die ('EMPTY ID');
  45.  
  46.  
  47.  
  48. $sql = "SELECT `num`,`code` FROM `$coupon_table` WHERE `id`=\"$id\";";
  49.  
  50. $result = mysqli_query($conn,$sql);
  51.  
  52. if ($result)
  53. if (mysqli_num_rows($result)>0)
  54. die ('COUPON USED');
  55.  
  56.  
  57. $sql = "SELECT `num`,`code` FROM `$coupon_table` WHERE `id`='' LIMIT 1;";
  58.  
  59. $result = mysqli_query($conn,$sql);
  60.  
  61. if ($result)
  62. if (mysqli_num_rows($result)==0)
  63. die ('ALL COUPONS USED');
  64.  
  65. $str_res = mysqli_fetch_row($result);
  66.  
  67. echo json_encode($str_res);
  68.  
  69.  
  70. $num = $str_res[0];
  71.  
  72. $sql = "UPDATE `$coupon_table` SET `id`=\"$id\" WHERE `num`=$num;";
  73. //echo $sql;
  74. $result = mysqli_query($conn,$sql);
  75.  
  76.  
  77. //print_r($str_res);
  78.  
  79. }
  80.  
  81.  
  82.  
  83. ?>
Add Comment
Please, Sign In to add comment