forked from steve011/booklocator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.php
148 lines (126 loc) · 3.92 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
#!/usr/local/bin/php
<?php require ('../connect.php'); ?>
<html><head><title>PHP Test</title></head>
<body>
<h2>Search</h2>
<table CELLSPACING=5>
<tr>
<form method="post" action="<?=$PHP_SELF?>">
<td>Seach for Book:</td>
<td>
<Select NAME="field" width="120" style="width: 120px">
<Option VALUE="Title">Title</option>
<Option VALUE="Author">Author</option>
<Option VALUE="ISBN">ISBN</option>
<Option VALUE="Year_Of_Publication">Year Published</option>
</Select>
</td>
<td><input type="text" name="find" width="180" style="width: 180px"/></td>
<input type="hidden" name="searching" value="Books" />
<td><input type="submit" /></td>
</form>
</tr>
<tr>
<form method="post" action="<?=$PHP_SELF?>">
<td>Seach for User: </td>
<td>
<Select NAME="field" width="120" style="width: 120px">
<Option VALUE="User_ID">Username</option>
<Option VALUE="Location">Location</option>
<Option VALUE="Age">Age</option>
</Select>
</td>
<td> <input type="text" name="find" width="180" style="width: 180px"/></td>
<input type="hidden" name="searching" value="Users" />
<td><input type="submit" /></td>
</form>
</tr>
<tr>
<form method="post" action="<?=$PHP_SELF?>">
<td>Seach for Rating: </td>
<td>
<Select NAME="field" width="120" style="width: 120px">
<Option VALUE="User_ID">Username</option>
<Option VALUE="ISBN">ISBN</option>
<Option VALUE="Book_Rating">Book Rating</option>
</Select>
</td>
<td><input type="text" name="find" width="180" style="width: 180px"/></td>
<input type="hidden" name="searching" value="Ratings" />
<td><input type="submit" /></td>
</form>
</tr>
</table>
<p>
<form method="post" action="<?=$PHP_SELF?>">
Enter SQL Command: <br><textarea cols="65" rows="5" name="my_query">
SELECT [] FROM [] WHERE [] GROUP BY [] HAVING [] ORDER BY []
UPDATE [] SET [] WHERE []
ALTER TABLE [] {ADD, MODIFY, DROP, RENAME...} </textarea><br>
<input type="hidden" name="searching" value="Query" />
<input type="submit" />
</form>
<?php
$my_query = $_POST["my_query"];
$find = $_POST["find"];
$field = $_POST["field"];
$searching = $_POST["searching"];
if ($searching == "Books"
|| $searching == "Users"
|| $searching == "Ratings"
|| $searching == "Query"
) {
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
if ($find == "" && $my_query == "") {
echo "<p>You forgot to enter a search term";
exit;
}
$stid_count = 0;
if($searching == "Query"){
$query = "$my_query";
$stid_count = oci_parse($connection, "SELECT COUNT(*) FROM ($query)");
}
else{
$query = "SELECT * FROM $searching WHERE UPPER($field) LIKE '%$find%'";
$stid_count = oci_parse($connection, "SELECT COUNT(*) FROM ($query)");
$query .= " AND ROWNUM <= 1000";
}
echo "<h2>Results</h2><p>";
echo "<h4>$query</h4><p>";
print '<table border="1">';
$stid = oci_parse($connection, "$query");
if(oci_execute($stid)){
print '<tr>';
echo "<p><b> Results found: ";
oci_execute($stid_count);
$count = current(oci_fetch_array($stid_count, OCI_RETURN_NULLS+OCI_ASSOC));
echo "$count</b><p>";
print '</tr>';
if($count){
$ncols = oci_num_fields($stid);
print '<tr>';
for ($i = 1; $i <= $ncols; $i++) {
$column_name = oci_field_name($stid, $i);
echo "<td><b>$column_name</b></td>";
}
print '</tr>';
}
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC)) {
print '<tr>';
foreach ($row as $item) {
print '<td>'.($item !== null ? htmlentities($item, ENT_QUOTES) : ' ').'</td>';
}
print '</tr>';
}
}
else{
echo "<p>Invaid query, please try again.";
}
print '</table>';
oci_free_statement($stid);
}
oci_close($connection);
?>
</body></html>