I am trying to pull all badges associated to a particular user that is logged into my site. On my index.php page I have,
<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
print_r(get_badges($_SESSION['user_id'], $mysqli));
?>
My db_connect.php:
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
and on my functions.php I have,
<?php
function get_badges($u, $mysqli){
$badges[] = array();
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$query = "SELECT * FROM memBadges WHERE ownerId = $u";
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
$badges[] = $row["badgeId"]);
}
}
$mysqli->close();
return $badges;
}
?>
The problem is that the piece in the functions.php page makes my page go blank. When I remove it, the page looks normal. What am I doing wrong?
$mysqliinside the functionget_badges()if it is not defined asglobal?echo 123; exit;as the first line of the script. Run. See 123? Now move it a line below. Continue until you know what causes the script to die. Tell us.