DisplayLandlord PHP: I couldn't get the output.The query is not fetching the result
<?php include("dbconfig.php"); ?>
<?php
$query = "SELECT * FROM rmuruge4_landlord";
$result = mysqli_query(mysqli_connect(),$query);
if ($result === false)
{die(mysqli_error(mysqli_connect())); }
echo "<div class='bs-example'>";
echo "<table class='table table-striped'>";
echo "<tr><th>LLID</th><th>LName</th><th>Phone</th><th>Address</th></td>";
while($row = mysqli_fetch_array($result)){
echo "<tr><td>" . $row['LLID'] . "</td><td >" . $row['LName'] . "</td><td >". $row['Phone'] . "</td><td >" . $row['Address'] . "</td></tr>"; }
echo "</table>";
echo "</div>";
mysqli_close(mysqli_connect());
?>
dbconfig.php:
Connection is successful
A bit in "wild-guessing mode", but ....
<?php
require 'dbconfig.php';
// let's assume dbconfig.php provides DB_HOST, DB_USER, ...
// there's something to be said about defining DB_PASS ...but anyway, that's worth another question
// establish the connection/create connection instance
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DBNAME);
if ($mysqli->connect_errno) {
trigger_error( sprintf('mysqli connect error (%d) %s', $mysqli->connect_errno, $mysqli->connect_error), E_USER_ERROR);
die;
}
$query = 'SELECT * FROM rmuruge4_landlord';
// use _that_ connection resource to send/retrieve data to/from the MySQL server
$result = mysqli_query($mysqli ,$query);
if ($result === false) {
// by default you shouldn't send the exact, detailed error message to the client
// see https://www.owasp.org/index.php/Information_Leakage
// die(mysqli_error(mysqli_connect()));
someErrorHandler( mysqli_error($mysql) );
}
else {
// php supports multi-line string literals
echo '
<div class="bs-example">
<table class="table table-striped">
<tr><th>LLID</th><th>LName</th><th>Phone</th><th>Address</th></tr>
';
while( $row=mysqli_fetch_array($result) ) {
// echo can take more than one parameter, no need to use string-concatenation here.
echo
'<tr><td>',
// just like you have to ensure the proper encoding when putting literal string values into sql statements
// you have to use something like htmlspecialchars() here to prevent, e.g. the value in Address to break your html structure
htmlspecialchars($row['LLID']),
'</td><td >',
htmlspecialchars($row['LName']),
'</td><td >',
htmlspecialchars($row['Phone']),
'</td><td >',
htmlspecialchars($row['Address'])
'</td></tr>'
;
}
echo '
</table>
</div>';