-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_cash_code.php
More file actions
executable file
·77 lines (69 loc) · 2.02 KB
/
validate_cash_code.php
File metadata and controls
executable file
·77 lines (69 loc) · 2.02 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
$LOG = false;
if( !empty($_POST) )
{
$seller_id = $_POST['seller_id'];
$cash_code = $_POST['cash_code'];
$book_cost = intval($_POST['book_cost']);
//echo "seller_id = ".$seller_id."\n";
//echo "cash_code = ".$cash_code."\n";
//echo "book_cost = ".$book_cost."\n";
}
else
{
$json_array = array();
$json_array["success"] = false;
echo json_encode($json_array);
exit;
}
if( $LOG )
{
$log_string = "Date: ".date('m-d-Y, g:i A', time())."\nsellerId: ".$seller_id."\ncashCode = ".$cash_code."\nbook_cost = ".$book_cost."\n\n\n";
//echo $log_string;
$log_success = file_put_contents( "/home/scott/gnt_logs/validate_cash_code.log", $log_string, FILE_APPEND );
// var_dump( $log_success );
}
$db = new mysqli("localhost", "scott", "scott", "gntdb");
if(mysqli_connect_errno($db))
{
die("Error connecting to MySQL database:".mysqli_connect_error()."\n");
}
$sql = "SELECT * from sellers,cash_codes WHERE sellers.username='".$seller_id."' AND sellers.sellers_id=cash_codes.sellers_id AND cash_codes.cash_codes='".$cash_code."' AND book_cost IS NULL\n";
//echo $sql;
$json_array = array();
if( $q = $db->query($sql) )
{
//echo "returned a value\n";
if( $q->num_rows == 0 )
{
$json_array["success"] = false;
}
else
{
$row = $q->fetch_assoc();
$seller_id_num = $row["sellers_id"];
//echo "seller_id_num = ".$seller_id_num."\n";
$newDate = date('Y-m-d');
//echo $newDate;
//echo "\n";
$sql2 = "UPDATE cash_codes SET book_cost='".$book_cost."', date_used='".$newDate."' WHERE sellers_id='".$seller_id_num."' AND cash_codes='".$cash_code."'\n";
//echo $sql2;
if( mysqli_query($db, $sql2) )
{
$json_array["success"] = true;
}
else
{
$json_array["success"] = false;
}
}
}
else
{
// echo "returned false";
$json_array["success"] = false;
}
$db->close();
echo json_encode($json_array);
//var_dump($json_array);
?>