I'm trying to fetch last_ip, last_ua, ui_walks, ui_lastwalk and ui_walkstotal from MySQL using PHP.
I want to assign each result (row) to a PHP variable.
Weird thing is that I dont get any error, just a blank page, with errors turned on ofc.
Tried on my localserver and with a public server (One.com) but nothing happens.
What am I doing wrong?
index.php
<?php
session_start();
include_once 'includes/db.config.php';
$_SESSION['user'] = "Dennis";
$user = mysqli_real_escape_string($connection, $_SESSION['user']);
$sql = "SELECT last_ip, last_ua, ui_walks, ui_lastwalk, ui_walkstotal FROM MyLog WHERE username=$user";
$result = mysqli_query($connection, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$lastip = $row['last_ip'];
$lastua = $row['last_ua'];
$uiwalks = $row['ui_walks'];
$uilastwalk = $row['ui_lastwalk'];
$uiwalkstotal = $row['ui_walkstotal'];
echo $lastip;
} else {
// No results
echo "No results";
}
?>
db.config.php
<?php
define ("HOST", "localhost");
define ("USER", "user");
define ("PASS", "pass");
define ("DB", "my_db");
$connection = mysqli_connect(HOST, USER, PASS, DB);
if (mysqli_connect_errno()) {
die("No database connection");
}
?>