I am trying to display data from a mySQL database table from with PHP code and am connecting successfully but am not returning any data.
I have tried several query styles, including mysql (unimproved) and get the same result: A blank area after the "Connected Successfully" echo.
I'd like to note that I used the exact same code to connect to a locally hosted database and was able to return data in a table. Are there mySQL permissions that may cause this or could be be differences between mySQL or php versions?
$servername = "server";
$username = "dbUser";
$password = "dbPass";
$datbase = "dbName";
$conn = mysqli_connect($servername, $username, $password, $database);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$result = mysqli_query($conn,"SELECT * FROM tableName ORDER BY selectedColumn");
$all_property = array();
echo '<table class="data-table">
<tr class="data-heading">';
while ($property = mysqli_fetch_field($result)) {
echo '<td>' . $property->name . '</td>';
array_push($all_property, $property->name);
}
echo '</tr>'; //end tr tag
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
foreach ($all_property as $item) {
echo '<td>' . $row[$item] . '</td>'; //get items using property value
}
echo '</tr>';
}
echo "</table>";
Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'Unknown column 'Station' in 'order clause''
in /var/www/html/wp-content/plugins/insert-php/insert_php.php(48) : eval()'d code:22 Stack trace: #0 /var/www/html/wp-content/plugins/insert-php/insert_php.php(48) : eval()'d code(22): mysqli_query(Object(mysqli), 'SELECT * FROM h...')
1 /var/www/html/wp-content/plugins/insert-php/insert_php.php(48): eval()
2 [internal function]: will_bontrager_insert_php('\r\n\r...')
3 /var/www/html/wp-includes/class-wp-hook.php(298): call_user_func_array('will_bontrager_...', Array)
4 /var/www/html/wp-includes/plugin.php(203): WP_Hook->apply_filters('\r\n\r...', Array)
5 /var/www/html/wp-includes/post-template.php(240): apply_filters('the_content', '\r\n\r...')