-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.php
55 lines (48 loc) · 1.35 KB
/
query.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
<html>
<head>
<?php $title = "CS143 Project 1B Demo" ?>
<title><?php print "$title"; ?></title>
</head>
<body bgcolor=white>
<h1><?php print "$title"; ?></h1>
<form action="./query.php" method="GET">
<textarea name="query" cols="60" rows="8"></textarea><br>
<input type="submit" value="Submit">
</form>
<?php
$query = $_GET["query"];
if ($query) {
$db = new mysqli('localhost', 'cs143', '', 'CS143');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
if (!($rs = $db->query($query))) {
$errmsg = $db->error;
print "Query failed: $errmsg <br />";
} else {
print '<table border="1" cellpadding="2" cellspacing="1">';
$fields = $rs->fetch_fields();
print '<tr align="center">';
foreach ($fields as $column) {
print '<td><b>';
print $column->name;
print '</b></td>';
}
print '</tr>';
while($row = $rs->fetch_assoc()) {
print '<tr align=center>';
foreach($row as $_ => $value) {
print '<td>';
print $value;
print '</td>';
}
print '</tr>';
}
print '</table>';
}
$rs->free();
$db->close();
}
?>
</body>
</html>