-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddGoalie.php
91 lines (79 loc) · 1.8 KB
/
addGoalie.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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
require_once "pdo.php";
session_start();
if ( ! isset($_SESSION['name']) )
{
die('Not logged in');
}
//
// This checks to make sure required variables are set and if they it then checks
// to make sure there is valid values.
// If all that goes through then it will execute a sql statement to add a new entry
//
if ( isset($_POST['goalie_name']))
{
if((strlen($_POST['goalie_name']) > 1))
{
$sql = "INSERT INTO goalies (goalie_name, wins, GAA)
VALUES (:goalie_name, :wins, :GAA)";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
':goalie_name' => $_POST['goalie_name'],
':wins' => $_POST['wins'],
':GAA' => $_POST['GAA']));
header('Location: index.php');
return;
}
}
//
// Redirects to index.php is cancel is selected
//
if(isset($_POST['cancel']))
{
header('Location: index.php');
return;
}
//
// Sends an error is the required variables have invalid values (empty)
//
if ( isset($_POST['goalie_name']) )
{
if(strlen($_POST['goalie_name']) < 1)
{
$_SESSION['error'] = "Goalie name is required";
header("Location: addGoalie.php");
return;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Beer League Database</title>
</head>
<body>
<h1>
Beer League Database
</h1>
<?php
if ( isset($_SESSION['error']))
{
if ( isset($_SESSION['error']) )
{
echo('<p style="color: red;">'.htmlentities($_SESSION['error'])."</p>\n");
unset($_SESSION['error']);
}
}
?>
<form method="post" id="addForm">
<p>Goalie Name:
<input type="text" name="goalie_name" size="60"/></p>
<p>Wins:
<input type="number" step=1 name="wins" size="60"/></p>
<p>GAA:
<input type="number" step="0.01" name="GAA"/></p>
</form>
<input type="submit" value="Add" form="addForm">
<input type="submit" name="cancel" value="Cancel" form="addForm">
</body>
</html>