Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- ini_set('display_errors', 1);
- $servername = 'localhost';
- $username = 'trackuser1';
- $password = 'trackSHIVA';
- $dbname = 'tracksmmdb';
- $coupon_table = 'coupon';
- $id_table = 'ident';
- function format_spec( $string, $separator = '-' )
- {
- return strtolower(preg_replace('/[^a-zA-Z0-9]/', $separator, $string));
- }
- $conn = mysqli_connect($servername,$username,$password)
- or die ('MySQL Not found // Could Not Connect.');
- mysqli_select_db($conn,"$dbname") or die ("No Database found.");
- if ( isset($_GET['id']) ){
- $id = format_spec($_GET['id']);
- //$sql = "SELECT 1 FROM ident WHERE id = $id";
- //$result = mysqli_query($conn,$sql);
- //$str_res = mysqli_fetch_row($result);
- //if ($str_res[0]!='1'){
- // die ('BAD ID');
- //}
- if ($id=='')
- die ('EMPTY ID');
- $sql = "SELECT `num`,`code` FROM `$coupon_table` WHERE `id`=\"$id\";";
- $result = mysqli_query($conn,$sql);
- if ($result)
- if (mysqli_num_rows($result)>0)
- die ('COUPON USED');
- $sql = "SELECT `num`,`code` FROM `$coupon_table` WHERE `id`='' LIMIT 1;";
- $result = mysqli_query($conn,$sql);
- if ($result)
- if (mysqli_num_rows($result)==0)
- die ('ALL COUPONS USED');
- $str_res = mysqli_fetch_row($result);
- echo json_encode($str_res);
- $num = $str_res[0];
- $sql = "UPDATE `$coupon_table` SET `id`=\"$id\" WHERE `num`=$num;";
- //echo $sql;
- $result = mysqli_query($conn,$sql);
- //print_r($str_res);
- }
- ?>
Add Comment
Please, Sign In to add comment