-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
237 lines (205 loc) · 7.25 KB
/
admin.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!DOCTYPE html>
<html lang="en">
<head>
<title>control panel</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<style>
footer {
background-color: #555;
color: white;
padding: 15px;
}
</style>
</head>
<body>
<br>
<br>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "et";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM game";
$result = $conn->query($sql);
$id =5;
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
if ($row['up']) {
echo "<div class='row' style='display: flex; align-items: center;justify-content: center; margin-top:25px ;'>
<div class='col-sm-9'>
<div class='well'>
<h4>update</h4>
id: ".$row['id']."  
name:<input type='text' id='namei' name='name' value=".$row['name'].">  price:<input type='text' id= 'pricei' name='price' value=".$row['price'].">   platform:<input id='pi' type='text' name='p' value=".$row['platform'].">
<button onclick='submit(".$row['id'].")'>submit</button></div></div></div>";
}
}
}
$conn->close();
?>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "et";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM game";
$result = $conn->query($sql);
$id =5;
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<div class='row' style='display: flex; align-items: center;justify-content: center; margin-top:25px ;'>
<div class='col-sm-9'>
<div class='well'>
id: ".$row['id']." | name : ".$row['name']."
<button style='float:right;'onclick='delet(".$row['id'].");'>delete</button>
<button style='float:right;'onclick='edit(".$row['id'].");'>details</button>
<button style='float:right;'onclick='up(".$row['id'].");'>update</button>
</div></div></div>";
if ($row['edit']) {
echo "
<div class='row' style='display: flex; align-items: center;justify-content: center; margin-top:25px ;'>
<div class='col-sm-9'>
<div class='well'><h4>Details</h4>
id: ".$row['id']." | name : ".$row['name']." | price: ".$row['price']."$ | platform : ".$row['platform']." </div></div></div>";
}
}
}
$conn->close();
?>
<form id="myForm" method="POST" action='<?php echo $_SERVER['PHP_SELF']; ?>'>
<input id='i' type='hidden' name='id'/>
<input id='ie' type='hidden' name='ide'/>
<input id='iu' type='hidden' name='idu'/>
</form>
<form id="myForm1" method="POST" action='<?php echo $_SERVER['PHP_SELF']; ?>'>
<input id='up' type='hidden' name='up'/>
<input id='name' type='hidden' name='name'/>
<input id='price' type='hidden' name='price'/>
<input id='p' type='hidden' name='p'/>
</form>
<div class='row' style='display: flex; align-items: center;justify-content: center; margin-top:25px ;'>
<a href="index.php"><button>go back</button></a></div>
<script type="text/javascript">
function delet(id){
document.getElementById("i").setAttribute('value',id);
document.getElementById("myForm").submit();
var result = "<?php
if (isset($_POST['id'])) {
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "et";
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = 'DELETE FROM game WHERE id='.$_POST['id'];
$result = $conn->query($sql);
}
?>";
}
function edit(id){
document.getElementById("ie").setAttribute('value',id);
document.getElementById("myForm").submit();
var result = "<?php
if (isset($_POST['ide'])) {
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "et";
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT * FROM game";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if ($_POST['ide']==$row['id']) {
if ($row['edit']==0) {
$sql = 'UPDATE `game` SET `edit`=1 WHERE id='.$_POST['ide'] ;
$conn->query($sql);
}else if($row['up']==1){
$sql = 'UPDATE `game` SET `edit`=0 WHERE id='.$_POST['ide'] ;
$conn->query($sql);};
}else{
$sql = 'UPDATE `game` SET `edit`=0 WHERE id='.$row['id'] ;
$conn->query($sql);}
}// the while
} // the first if
} // isset
?>";
}
function up(id){
document.getElementById("iu").setAttribute('value',id);
document.getElementById("myForm").submit();
var result = "<?php
if (isset($_POST['idu'])) {
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "et";
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT * FROM game";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if ($_POST['idu']==$row['id']) {
if ($row['up']==0) {
$sql = 'UPDATE `game` SET `up`=1 WHERE id='.$_POST['idu'] ;
$conn->query($sql);
}else if($row['up']==1){
$sql = 'UPDATE `game` SET `up`=0 WHERE id='.$_POST['idu'] ;
$conn->query($sql);};
}else{
$sql = 'UPDATE `game` SET `up`=0 WHERE id='.$row['id'] ;
$conn->query($sql);};
}// the while
} // the first if
} // isset
?>";
} //function
function submit(id){
let name = document.getElementById("namei").value;
let price = document.getElementById("pricei").value;
let platfrom = document.getElementById("pi").value;
alert('information updated to name:'+name+' price:'+price+' platfrom:'+platfrom);
document.getElementById("name").setAttribute('value',name);
document.getElementById("price").setAttribute('value',price);
document.getElementById("p").setAttribute('value',platfrom);
document.getElementById("up").setAttribute('value',id);
document.getElementById("myForm1").submit();
var result = "<?php
if (isset($_POST['name'])&&isset($_POST['price'])&&isset($_POST['p'])){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "et";
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT * FROM game";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$sql = "UPDATE `game` SET `name`='". $_POST['name'] ."',`price`='". $_POST['price'] ."',`platform`='". $_POST['p'] ."' WHERE id=". $_POST['up'];
$conn->query($sql);
}// the while
} // the first if
} // isset
?>";
}
</script>
</body>
</html>