-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_cash.php
41 lines (23 loc) · 926 Bytes
/
add_cash.php
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
<?php
include('database.php');
global $pdo;
if((isset($_POST["added_cash"]) && !empty($_POST["added_cash"])) && (isset($_POST["current_game_total"]) && !empty($_POST["current_game_total"]))){
$noDollarSign = str_replace("$", "",$_POST["added_cash"]); //remove user input dollar sign
if(!is_numeric($noDollarSign)){
header('Location: ./index.php'); //dont do anything if input is not numeric
}
try{
$addCash = floatval($noDollarSign);
$currentTotal = floatval($_POST["current_game_total"]);
$newTotal = $currentTotal + $addCash;
$sql="UPDATE casino_game SET gameTotalDollars =? WHERE gameInSession=1";
$updateTotal = $pdo->prepare($sql);
$updateTotal->execute(array($newTotal));
}catch(\Exception $e) {
echo "ERROR: " . $e->getMessage();
}
header('Location: ./index.php');
}else{
header('Location: ./index.php');
}
?>