ok i have been using the mysql format for quite a while but i figured its time to transfer my site over to the new mysqli format now rather then later. im trying to re write my functions to draw stats from the database but i am getting all sorts of errors.
I have looked at countless mysqli tuts but none are very descriptive and im not quite understanding the 2 parameter rule ect. below i posted my function and includes. if anyone can tell m what im doing wrong i would appreciate it.
Fatal error: Call to a member function fetch_assoc() on a non-object in C:\xampp\htdocs\includes\stat.php on line 7
stat.php
function getStat($stat) {
require_once 'includes/config.php';
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
$sql = $mysqli->query("SELECT $stat FROM players WHERE username = '".$_SESSION['username']."'");
$row = $sql->fetch_assoc();
$result = $row['$stat'];
return $result;
}
?>
and here is the test page i am using to try and get this working.
test.php
<?php
include 'includes/login-check.php';
include 'includes/config.php';
include 'includes/database.php';
include 'includes/stat.php';
echo getStat('name');
?>
ow and please dont start posting a bunch of comments bashing on the code cause as stated before ive never used mysqli so ide rather read constructive criticism then flames like half the post around here.