<html>
<head>
<title>Test MySql Stored Procedure SQL Code via PHP Results</title>
</head>
<body style='background-color:pink;'>
<?php

 if (isset($_POST['host'])) {
   $ourhost=$_POST['host'];
 } else {
   $ourhost="localhost:8889";
 }
 if (isset($_POST['user'])) {
   $ouruser=$_POST['user'];
 } else {
   $ouruser="root";
 }
 if (isset($_POST['password'])) {
   $ourpassword=$_POST['password'];
 } else {
   $ourpassword="root";
 }


 $con=mysqli_connect($ourhost, $ouruser, $ourpassword);
 // Check connection
 if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }
 mysqli_select_db($con, $_POST['db']);
 if (isset($_POST['spqy'])) {
  if (strlen($_POST['spqy']) > 0) {
   $rspes = stripSlashes($_POST['spqy']);
   echo "<details><summary>Creation of tables ...</summary><p>" . str_replace("\r\n","<br>",$rspes) . "</p></details>";
   $spres = mysqli_query($con, $rspes);
  }
 }
 if (isset($_POST['spqy2'])) {
  if (strlen($_POST['spqy2']) > 0) {
   $rspes = stripSlashes($_POST['spqy2']);
   echo "<details><summary>CREATE PROCEDURE GetLMax ...</summary><p>" . str_replace("\r\n","<br>",$rspes) . "</p></details>";
   $spres = mysqli_query($con, $rspes);
  }
 }
 if (isset($_POST['spqy3'])) {
  if (strlen($_POST['spqy3']) > 0) {
   $rspes = stripSlashes($_POST['spqy3']);
   echo "<details><summary>CREATE PROCEDURE GetPlaceMax ...</summary><p>" . str_replace("\r\n","<br>",$rspes) . "</p></details>";
   $spres = mysqli_query($con, $rspes);
  }
 }
 if (isset($_POST['spqy4'])) {
  if (strlen($_POST['spqy4']) > 0) {
   $rspes = stripSlashes($_POST['spqy4']);
   echo "<details><summary>CREATE PROCEDURE AddLine ...</summary><p>" . str_replace("\r\n","<br>",$rspes) . "</p></details>";
   $spres = mysqli_query($con, $rspes);
  }
 }
 $res = stripSlashes($_POST['qy']);
   echo "<p>" . str_replace("\r\n","<br>",$res) . "</p></details>";
 $mres = mysqli_query($con, explode(";", $res)[0]);
 if (sizeof(explode(";", $res)) > 1) {
   mysqli_close($con);
 $con=mysqli_connect($ourhost, $ouruser, $ourpassword);
 // Check connection
 if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }
 mysqli_select_db($con, $_POST['db']);
   $mres = mysqli_query($con, explode(";", $res)[1]);
 }
?>

Query results <b><?php echo str_replace("\r\n","<br>",$_POST['qy']); ?></b><hr>

<?php
if ($mres == 0):
  echo("<b>Error: " . mysqli_error($con) . "</b>");
elseif (mysqli_num_rows($mres) == 0):
  echo("<b>Query executed successfully</b>");
else:
?>
<table border=1>
<thead>
<tr>
<?php
$afs=explode(",", "lngfrom,latfrom,lngto,latto,distance");
for ($ii = 0; $ii < sizeof($afs); $ii++) {   
 echo "<th>" . $afs[$ii] . "</th>";
}
?>
</tr>
</thead>
<tbody>
<?php
for ($ii = 0; $ii < mysqli_num_rows($mres); $ii++) {
 echo("<tr>");
 $r_array = mysqli_fetch_row($mres);
 for ($jj = 0; $jj < mysqli_num_fields($mres); $jj++) {
 echo("<td>" . $r_array[$jj] . "</td>");
 }
 echo("</tr>");
}
?>
</tbody>
</table>
<?php
endif
//mysqli_close();
?>
<hr><br>
<a target=_blank href="./ourmysql_storedprocedure.php" title="Back">Back for more</a>
</body>
</html>

