/
delete.php
108 lines (96 loc) · 3.16 KB
/
delete.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
//connect to db
$link = mysqli_connect("#", "#", "#", "#") or die("Connect Error ". mysqli_error($link));//display non-editable textbox for attribute $key
//no table was provided, display error message
function fail() {
header("Location: fail.php");
}
//Save updated city
//Delete selected city
function deleteSport(){
global $link;
$sql = "DELETE FROM sport WHERE leagueName = ?";
if ($stmt = mysqli_prepare($link, $sql)) {//prepare successful
mysqli_stmt_bind_param($stmt, "s", $_POST['League']) or die("bind param");
if(mysqli_stmt_execute($stmt)) {//execute successful
echo "<h2>Successfully Delete Record</h2>";
} else {
fail();
}
mysqli_stmt_close($stmt);
}else { //prepare failed
fail();
}
echo "<a class='btn btn-info' href='statistics.php'>Back</a>";
}
//Save updated country
//Delete selected country
function deleteTeam(){
global $link;
$sql = "DELETE FROM team WHERE teamName = ?";
if ($stmt = mysqli_prepare($link, $sql)) {//prepare successful
mysqli_stmt_bind_param($stmt, "s", $_POST['TeamName']) or die("bind param");
if(mysqli_stmt_execute($stmt)) {//execute successful
echo "<h2>Successfully Delete Record</h2>";
} else {
fail();
}
mysqli_stmt_close($stmt);
}else { //prepare failed
fail();
}
echo "<a class='btn btn-info' href='statistics.php'>Back</a>";
}
//delete selected language
function deleteGame(){
global $link;
$sql = "DELETE FROM game WHERE gameID = ? ";
if ($stmt = mysqli_prepare($link, $sql)) {//prepare successful
mysqli_stmt_bind_param($stmt, "s", $_POST['GameID']) or die("bind param");
if(mysqli_stmt_execute($stmt)) {//execute successful
echo "<h2>Successfully Delete Record</h2>";
} else {
fail();
}
mysqli_stmt_close($stmt);
}else { //prepare failed
fail();
}
echo "<a class='btn btn-info' href='statistics.php'>Back</a>";
}
?>
<html>
<head>
<!-- I USE BOOTSTRAP BECAUSE IT MAKES FORMATTING/LIFE EASIER -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"><!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"><!-- Optional theme -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script><!-- Latest compiled and minified JavaScript -->
</head>
<body>
<div class="container">
<?php
if(isset($_POST['delete'])){//sumbit came from index.php when delete button selected.
if(isset($_POST['table'])){//do we have table information
switch($_POST['table']){//what table are we deleting
case "sport":
deleteSport();
break;
case "team":
deleteTeam();
break;
case "game":
deleteGame();
break;
default;
fail();
break;
}
}
}
?>
</div>
</body>
</html>
<?php
mysqli_close($link);
?>