-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrewardredeem.php
More file actions
49 lines (40 loc) · 1.35 KB
/
rewardredeem.php
File metadata and controls
49 lines (40 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
session_start();
require_once "pdo.php";
sleep(1);
if ( ! isset($_SESSION['phone']) ) {
$_SESSION['error'] = "Missing phone number";
header('Location: deal.php');
return;
}
if ( ! isset($_POST['rid']) ) {
header('Location: deal.php');
return;
}
$phone = $_SESSION['phone'];
$rid = $_POST['rid'];
$stmt = $pdo->prepare("SELECT * FROM reward where rid = :rid");
$stmt->execute(array(":rid" => $rid));
$reward = $stmt->fetchAll(PDO::FETCH_ASSOC);
$phone = $_SESSION['phone'];
$stmt = $pdo->prepare("SELECT * FROM users where phone = :phone");
$stmt->execute(array(":phone" => $phone));
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($reward) {
if ($user['coinamount'] >= $reward[0]['coinprice']) {
$balance = $user['coinamount'] - $reward[0]['coinprice'];
$stmt = $pdo->query("UPDATE users SET coinamount='$balance' where phone='$phone'");
$stmt->execute();
$stmt1 = $pdo->prepare("INSERT into claim (phone, rid) values ('$phone', '$rid')");
$stmt1->execute();
}
else {
header('HTTP/1.1 9999 NOT ENOUGH COIN');
die(json_encode(array('message' => 'NOT ENOUGH COIN', 'code' => 9999)));
}
}
else {
header('HTTP/1.1 9998 REWARD DOES NOT EXIST');
die(json_encode(array('message' => 'REWARD DOES NOT EXIST', 'code' => 9998)));
}
?>