-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit_edit.php
131 lines (122 loc) · 4.16 KB
/
submit_edit.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!doctype html>
<html>
<head>
<?php
error_reporting(-1);
include('connection.php');
?>
<meta charset="utf-8">
<title>Prisoner's Dilemma</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/stylesheet.css" rel="stylesheet">
<link href="css/custom.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/zsparks.js"></script>
<style>
#message
{
width: 50%;
margin: 2% 40%;
}
</style>
</head>
<body>
<!-- Navigation Bar begin-->
<header class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand/Logo and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapse" aria-expanded="false">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">Prisoner's Dilemma</a>
</div>
<!-- Collect the nav links and other content for toggling -->
<div class="collapse navbar-collapse" id="collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="index.php">Home</a></li>
<li class="active"><a href="editgame.php">Edit Game</a></li>
<li ><a href="administration.php">Check Scores</a></li>
<li class="dropdown">
<a href="" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">My Account <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="profilepage.php">My Profile</a></li>
<li role="separator" class="divider"></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</header><!-- end Navigation Bar -->
<div id='message'>
<?php
//get the query
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$course = $_POST['course'];
$section = $_POST['section'];
$password = $_POST['pwd'];
$id = $_POST['id'];
$userTag = $_POST['userTag'];
//returns true or false for update on everything except tag
$result = mysqli_query($dbc, "UPDATE users SET first_name = '$fname', last_name = '$lname',
course = '$course', section = '$section', pw = '$password' where id = $id");
if (!$result)
{
print "Error - the query could not be executed: <br/>" . mysqli_error($dbc);
exit;
}
//the following code is to change the tag
if ($userTag != NULL && (strtolower(substr($userTag,0,1)) == 'r' || strtolower(substr($userTag,0,1)) == 'y' || strtolower(substr($userTag,0,1)) == 'b'))
{
if (strtolower(substr($userTag,0,1)) == 'r')
{
$usrgroup = "Red";
}
elseif (strtolower(substr($userTag,0,1)) == 'b')
{
$usrgroup = "Blue";
}
elseif (strtolower(substr($userTag,0,1)) == 'y')
{
$usrgroup = "Yellow";
}
$result = mysqli_query($dbc, "SELECT * FROM teamcode WHERE user_group = '$usrgroup'");
$num_rows = mysqli_num_rows($result);
$i=0;
while ($i < 5) //attempt only a max of 5x to insert a tag
{
$tag = ucfirst($usrgroup)."-".$num_rows++;
$result = mysqli_query($dbc, "SELECT * FROM teamcode WHERE tag = '$tag'");
//echo $tag;
if(mysqli_affected_rows($dbc) < 1)
{
$result = mysqli_query($dbc, "UPDATE teamcode SET tag = '$tag', user_group = '$usrgroup' where users_id = $id");
break;
}
$i++;
}
}
//if everything was ok:
if(mysqli_affected_rows($dbc) == 1)
{
//Ok message confirmation:
echo "Great. This account has been updated. <br/>";
echo '<a href="editgame.php">Return to tables</a>';
}else{
echo "The account could not be changed due to a system error. <br/>";
echo '<a href="editgame.php">Return to tables</a>';
}
mysqli_query($dbc, "COMMIT");
//3. ALWAYS CLOSE A DATABASE AFTER USING IT.
mysqli_close($dbc); //dbc is for connection.php
?>
</div>
</body>
</html>