-
Notifications
You must be signed in to change notification settings - Fork 1
/
start_new_game.php
42 lines (24 loc) · 995 Bytes
/
start_new_game.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
42
<?php
include('database.php');
global $pdo;
if(isset($_POST["dollar-amount"]) && (isset($_POST["player-name"]) && !empty($_POST["player-name"]))){
$noDollarSign = str_replace("$", "",$_POST["dollar-amount"]); //remove user input dollar sign
if(!is_numeric($noDollarSign)){
header('Location: ./index.php'); //dont do anything if input is not numeric
}
try{
$dollar = floatval($noDollarSign);
$name = $_POST["player-name"];
date_default_timezone_set("America/New_York");
$date = date('Y-m-d H:i:s');
$sql="INSERT INTO casino_game (gameInSession, gamePlayNumber, gamePlayerName, gameLastPlayedDate, gameTotalDollars, gameStartDate) VALUES(?,?,?,?,?,?)";
$newGame = $pdo->prepare($sql);
$newGame->execute(array(true, 0, $name, $date, $dollar, $date));
}catch(\Exception $e) {
echo "ERROR: " . $e->getMessage();
}
header('Location: ./index.php');
}else{
header('Location: ./index.php');
}
?>