/
admineditadmins.php
169 lines (115 loc) · 3.71 KB
/
admineditadmins.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
<!DOCTYPE html>
<html>
<head>
<title>Database Management</title>
<link rel="stylesheet" type="text/css" href="cssindex.css" />
</head>
<body>
<?php require 'menu.php';?>
<?php
if(isset($_SESSION['adminstatus']) && $_SESSION['adminstatus']==true)
{
$connect = mysql_connect("localhost", "root", '');
if (!$connect)
{
die("Could not connect to DB at this time, error:" . mysql_error());
}
mysql_select_db("alicinamemar", $connect);
$id=$_GET['id'];
//INSERT CODE
if ($id=="I")
{
echo '
<h2>Insert New Admin</h2>
<table cellpadding="5">
<form name = "login" method ="post">
<tr>
<td><b>Username</b></td>
<td><input name="username" id="username" type="text"></td>
</tr>
<tr>
<td><b>Password</b></td>
<td> <input name="password" id="password" type="password"></td>
</tr>
<tr>
<td></td>
<td><input style="cursor:pointer" type="submit" name="submit" value="Submit"></td>
</tr>
</form>
</table>
';
if ( $_POST )
{
$username = $_POST['username'];
$password = $_POST['password'];
$checkuserexistence =
"
SELECT username FROM `admins` WHERE username='$username'
";
$checkuserexistence = mysql_query($checkuserexistence);
$checkuserexistence = mysql_num_rows($checkuserexistence);
if($checkuserexistence>=1)
{
echo "<h2>Username exists. Please try a new Username</h2>";
}
else
{
$insertion =
"
INSERT INTO `alicinamemar`.`admins` (`id`, `username`, `password`) VALUES (NULL, '$username', '$password')
";
mysql_query($insertion);
mysql_close($connect);
header("Location: admindbmanagement.php");
}
}
//END INSERT
}
//START EDIT
else
{
$view = "
SELECT * FROM `admins` WHERE id='$id'
";
$view = mysql_query($view);
$rowselect= mysql_fetch_array($view);
echo "<h2>Edit Admin</h2>";
echo '<table cellpadding="5">
<form name = "login" method ="post">
<tr>
<td><b>Username</b></td>
<td><input name="username" id="username" type="text" value="';
echo $rowselect["username"] . '"></td>
</tr>
<tr>
<td><b>Password</b></td>
<td> <input name="password" id="password" type="password" value="';
echo $rowselect["password"] . '"></td>
</tr>
<tr>
<td></td>
<td><input style="cursor:pointer" type="submit" name="submit" value="Submit"></td>
</tr>
</form>
</table>
';
}
if ( $_POST )
{
$username= $_POST["username"];
$password = $_POST["password"];
$update ="
UPDATE `alicinamemar`.`admins` SET `username` = '$username',
`password` = '$password'
WHERE `admins`.`id` = '$id'
";
mysql_query($update);
mysql_close($connect);
header("Location: admindbmanagement.php");
}
} //end if tag
else
{
echo "<h2>Admin must be logged in</h2>";
}
?>