Skip to content
This repository was archived by the owner on Sep 23, 2022. It is now read-only.

Commit a68ff03

Browse files
author
NerdOfLinux
authored
Update mysql_exec.php
Improved MySQL query output
1 parent 933e3a6 commit a68ff03

1 file changed

Lines changed: 25 additions & 14 deletions

File tree

mysql_exec.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,30 @@
3333
</body>
3434

3535
<?php
36-
$udb=$_POST['mysql_get'];//Database
37-
$user=$_POST['username'];
38-
$pass=$_POST['password'];
39-
$query=$_POST['myquery'];//Commands
40-
$host=$_POST['host'];
41-
//Set all current values as session variables below
42-
$_SESSION['saved_info']="1";$_SESSION['udb']="$udb";$_SESSION['mysql_user']="$user";$_SESSION['mysql_pass']="$pass";$_SESSION['query']="$query";$_SESSION['host']="$host";
43-
$db = mysqli_connect($host,$user,$pass,$udb) or die("<p style=\"color:red;\"><b>Error: </b> connection to MySQL failed. Please re-enter information and try again.</p>");
44-
mysqli_query($db, $query) or die("Unable to access MYSQL");
45-
$result = mysqli_query($db, $query);
46-
$row = mysqli_fetch_array($result);
47-
$column=$row['password'];
48-
echo "<b>Query Result: $column</b><br>";
49-
$mysqli_close($db);
36+
$udb=$_POST['mysql_get'];//Database
37+
$user=$_POST['username'];
38+
$pass=$_POST['password'];
39+
$query=$_POST['myquery'];//Commands
40+
$host=$_POST['host'];
41+
//If the variables are not empty, continue
42+
if (!empty($udb, $user, $pass, $query, $host)){
43+
//Set all current values as session variables below
44+
$_SESSION['saved_info']="1";$_SESSION['udb']="$udb";$_SESSION['mysql_user']="$user";$_SESSION['mysql_pass']="$pass";$_SESSION['query']="$query";$_SESSION['host']="$host";
45+
echo "<br> MySQL Query results: <br>";
46+
include("data.php");
47+
$databaseName = $_POST[mysql_get];
48+
$query = $_POST[myquery];
49+
$db = mysqli_connect($host,$user,$pass,$udb) or die("<p style=\"color:red;\"><b>Error: </b> connection to MySQL failed. Please re-enter information and try again.</p>");
50+
mysqli_query($db, $query) or die("Unable to access MYSQL DataBase");
51+
$result = mysqli_query($db, $query);
52+
$row = mysqli_fetch_all($result, MYSQLI_ASSOC);
53+
$stringArray = json_encode($row);
54+
$stringArray = str_replace(",", "<br>", $stringArray);
55+
$stringArray = str_replace(array('[', ']', '}', '"'), "", $stringArray);
56+
$stringArray = str_replace("{", "<br>", $stringArray);
57+
$stringArray = str_replace(":", ": ", $stringArray);
58+
echo $stringArray;
59+
$mysqli_close($db);
60+
}
5061
?>
5162
</html>

0 commit comments

Comments
 (0)