I have a PHP script that tests various functions of a LAMP environment, namely phpmail, mysql connections, and a phpinfo. For some reason, whenever I test the database connection and submit the form, no results are displayed. However, if you check the source, the results are shown in the source text but don't come up on the page itself. I've been looking at this all weekend and I'm at a loss.
Pastebin here: https://pastebin.com/SsKyFutK
DB Connection code here:
<div id="test_area" class="col-sm-8 tab-content">
<div class="dbConnectionTest tab-pane" id="db-connect" role="tabpanel" aria-labelledby="db-connect-link">
<?php
// Check to see if the form was submitted
if (isset($_POST['host'])) {
$dbhost = $_POST['host'];
$dbname = $_POST['database'];
$dbuser = $_POST['user'];
$dbpass = $_POST['pwd'];
$dbport = $_POST['port'];
if (strlen($dbport) < 4) { $dbport = 3306; }
if (!function_exists('gethostname')) {
$hostname = `hostname`;
$hostnamearray = explode('.', $hostname);
$hostname = $hostnamearray[0];
}
else $hostname = gethostname();
// Check to see if mysqli is available
if (!extension_loaded('mysqli') or $_POST['config'] == "mysql") {
$dbhost = $dbhost.':'.$dbport;
// Create connection
$con = @mysql_connect($dbhost,$dbuser,$dbpass);
// Check connection
if (mysql_error()) {
die("Failed to connect to MySQL using the PHP mysql extension: " . mysql_error());
}
mysql_select_db($dbname, $con);
// Query the database to show all the tables.
$query = 'SHOW tables;';
$result = mysql_query($query);
// Print the results of the query.
echo "Here is a list of the tables in your database:<br>";
echo "- $dbname <br>";
while($row = mysql_fetch_array($result)) {
echo "\ _ _ $row[0] <br>";
}
echo "<br>The connection to \"$dbname\" was successful!";
$extension = "MySQL";
mysql_close($con);
}
else {
// Create connection
$con = @mysqli_connect($dbhost,$dbuser,$dbpass,$dbname,$dbport);
// Check connection
if (mysqli_connect_errno()) {
die ("Failed to connect to MySQL using the PHP mysqli extension: " . mysqli_connect_error());
}
// Query the database to show all the tables.
$query = 'SHOW tables;';
$result = mysqli_query($con, $query);
// Print the results of the query.
echo "Here is a list of the tables in your database:<br>";
echo "- $dbname <br>";
while($row = mysqli_fetch_array($result)) {
echo "\ _ _ $row[0] <br>";
}
echo "<br>The connection to \"$dbname\" was successful!";
$extension = "MySQLi";
mysqli_close($con);
}
echo "<br>PHP extension used: " . $extension;
echo "<br>Server Name: " . $hostname;
unset($_POST);
}
// If we are not here because of a form submission, do the following.
else { ?>
<div class="card">
<div class="card-body">
<h3 class="card-title">Database Connection Test</h3>
<form method="post">
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="config">Connection:</label>
<div class="col-sm-9">
<select class="form-control form-control-sm" name="config" id="config">
<option value="auto" selected>Auto Select</option>
<option value="mysqli">MySQLi</option>
<option value="mysql">MySQL</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="host">Host Name:</label>
<div class="col-sm-9">
<input type="text" class="form-control form-control-sm" id="host" name="host" autofocus>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="database">DB Name:</label>
<div class="col-sm-9">
<input type="text" class="form-control form-control-sm" id="database" name="database">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="user">User:</label>
<div class="col-sm-9">
<input type="text" class="form-control form-control-sm" id="user" name="user">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="pwd">Password:</label>
<div class="col-sm-9">
<input type="password" class="form-control form-control-sm" id="pwd" name="pwd">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="port">Port (optional):</label>
<div class="col-sm-9">
<input type="nubmer" class="form-control form-control-sm" id="port" name="port" min="1" max="65535" value="3306">
</div>
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary">Connect</button>
</div>
</form>
</div>
</div>
<?php
}
?>
</div>
If anyone out there could lend a hand, I'd greatly appreciate it.
edit: Here's the code in the source that does not show up on the rendered page, from a test account on GD:
<body>
<header>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<span class="navbar-brand mb-0 h1">Does PHP Work?</span>
</nav>
</header>
<div class="container-fluid wt-mt">
<div class="row">
<div class="col-sm-2 text-center">
<div class="nav flex-column" role="tablist" aria-orientation="vertical">
<a class="nav-link" id="db-connect-link" data-toggle="pill" href="#db-connect" role="tab" aria-controls="db-connect" aria-selected="true">DB Connection Test</a>
<a class="nav-link" id="form-mail-link" data-toggle="pill" href="#form-mail" role="tab" aria-controls="form-mail" aria-selected="false">Form Mailer Test</a>
<a class="nav-link" id="php-info-link" data-toggle="pill" href="#php-info" role="tab" aria-controls="php-info" aria-selected="false">PHP Info</a>
</div>
</div>
<div id="test_area" class="col-sm-8 tab-content">
<div class="dbConnectionTest tab-pane" id="db-connect" role="tabpanel" aria-labelledby="db-connect-link">
Here is a list of the tables in your database:<br>- hurdywordy <br>\ _ _ wp_commentmeta <br>\ _ _ wp_comments <br>\ _ _ wp_links <br>\ _ _ wp_options <br>\ _ _ wp_postmeta <br>\ _ _ wp_posts <br>\ _ _ wp_term_relationships <br>\ _ _ wp_term_taxonomy <br>\ _ _ wp_termmeta <br>\ _ _ wp_terms <br>\ _ _ wp_usermeta <br>\ _ _ wp_users <br><br>The connection to "hurdywordy" was successful!<br>PHP extension used: MySQLi<br>Server Name: p3plcpnl0520.prod.phx3.secureserver.net </div>