I am a beginner at PHP and I don't understanding why the code below isn't displaying the user name, as there are no error messages. I have double checked my work and I still can't find an error.
$sql = "SELECT * FROM users";
$result = query($sql);
confirm($result);
$row = fetch_array($result);
echo $row['username'];
?>
This is the db.php
file I have created:
<?php
$con = mysqli_connect('localhost','root','','login_db');
function escape($string) {
global $con;
return mysqli_real_escape_string($con, $string);
}
function query($query) {
global $con;
return mysqli_query($con,$query);
}
function fetch_array($result){
global $con;
mysqli_fetch_array($result);
}
function confirm($result) {
global $con;
if(!$result) {
die("Query Failed" . mysqli_error($con));
}
}
?>