-
Notifications
You must be signed in to change notification settings - Fork 1
/
sql-old.php
133 lines (98 loc) · 2.88 KB
/
sql-old.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
<?PHP
session_start();
$ADMIN_PAGE = true;
require_once('./_INCLUDES/00_SETUP.php');
require_once("./_INCLUDES/config.php");
include_once './_INCLUDES/dbconnect.php';
//echo "Logged in:" . $LOGGED_IN ? 'true' : 'false';;
if ($LOGGED_IN == true && $_SESSION['Admin'] == true) {
$msg = "";
if (isset($_GET["m"])){
$msg = 'SQL executed!';
$sql = $_POST["sql"];
$pieces = explode(" ", $sql );
$command = strtoupper($pieces[0]);
}
else {
$msg = 'Default SQL used...';
$sql = 'SELECT id_user, username, name, email FROM users ORDER BY id_user';
$command = 'SELECT';
}
?><!DOCTYPE HTML>
<html>
<head>
<title>Useful Stuff</title>
<?php include_once './_INCLUDES/01_HEAD.php'; ?>
<style>
#sql {
width: 100%;
height: 100px;
padding: 10px;
margin-bottom: 1em;
}
button.submit {
margin-bottom: 1em;
}
</style>
</head>
<body>
<div id="page">
<?php include_once './_INCLUDES/02_NAV.php'; ?>
<div id="main">
<h1>SQL EXECUTOR 1.0</h1>
<div><?=$msg?></div>
<div style="padding:40px; margin:20px;">
<p><u>Examples</u></p>
<p>SELECT id_user, username, name, email FROM users ORDER BY id_user DESC</p>
<p>UPDATE users SET name='Matt' WHERE id_user = 2</p>
<form method="post" action="sql.php?m=1">
<textarea id="sql" name="sql"><?php print $sql; ?></textarea>
<button type="submit" class="submit">Submit</button>
<?php
$servername = "localhost";
$username = "nhl94";
$password = "Mysp@ce2174";
$dbname = "nhl94db";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//$sql = "SELECT id_user, username, name, email FROM users ORDER BY id_user";
$result = $conn->query($sql);
if ($command == 'SELECT') {
print '<table><tr><td><b>id_user</b></td><td><b>username</b></td><td><b> name</b></td><td><b>email</b></td></tr>';
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
print "<tr><td>" . $row["id_user"] . "</td><td>" . $row["username"] . "</td><td>" . $row["name"] . "</td><td>" . $row["email"] . "</td></tr>";
}
} else {
print '<tr><td colspan="4">0 results</td></tr>';
}
}
print '</table>';
$conn->close();
?>
</form>
</div>
</div>
</div><!-- end: #page -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="./js/default.js"></script>
<script>
$(function() {
$( "button.submit" ).click(function() {
document.forms[0].submit();
});
});
</script>
</body>
</html>
<?php
}
else {
header('Location: index.php');
}
?>