-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmineditcomments.php
More file actions
158 lines (115 loc) · 3.49 KB
/
admineditcomments.php
File metadata and controls
158 lines (115 loc) · 3.49 KB
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
<!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 comment</h2>';
echo '<form method="post">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="fullname" id="fullname"/></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="email" name="email" id="email"/></td>
</tr>
<tr>
<td>Comments:<br></td>
<td><textarea name="comments" id="comments"></textarea></td>
</tr>
<tr>
<td><input style="cursor:pointer" type="reset" /></td>
<td><input style="cursor:pointer" type="submit" value="Submit" /></td>
</tr>
</table>
</form>';
if( $_POST )
{
$name = $_POST['fullname'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$name = mysql_real_escape_string($name);
$email = mysql_real_escape_string($email);
$comments = mysql_real_escape_string($comments);
$name = stripslashes($name);
$email = stripslashes($email);
$comments = stripslashes($comments);
$insertion =
INSERT INTO `alicinamemar`.`comments` (`id`, `name`, `email`, `comments`, `time`) VALUES (NULL, '$name', '$email', '$comments', CURRENT_TIMESTAMP)
";
mysql_query($insertion);
mysql_close($connect);
header("Location: admindbmanagement.php");
}
//END INSERT
}
//START EDIT
else
{
$view =
SELECT * FROM `comments` WHERE id='$id'
";
$view = mysql_query($view);
$rowselect= mysql_fetch_array($view);
echo "<h2>Edit Item</h2>";
echo '<form method="post">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="fullname" id="fullname" value="';
echo $rowselect["name"] . '"/></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="email" name="email" id="email" value="';
echo $rowselect["email"] . '"/></td>
</tr>
<tr>
<td>Comments:<br></td>
<td><textarea name="comments" id="comments">';
echo $rowselect["comments"] . '</textarea></td>
</tr>
<tr>
<td><input style="cursor:pointer" type="reset" /></td>
<td><input style="cursor:pointer" type="submit" value="Submit" /></td>
</tr>
</table>
</form>';
if ( $_POST )
{
$name = $_POST["fullname"];
$email = $_POST["email"];
$comments = $_POST["comments"];
$update =
UPDATE `alicinamemar`.`comments` SET `name` = '$name',
`email` = '$email', `comments` = '$comments'
WHERE `comments`.`id` = '$id'
";
mysql_query($update);
mysql_close($connect);
header("Location: admindbmanagement.php");
}
}
} //end if tag
else
{
echo "<h2>Admin must be logged in</h2>";
}
?>