I’m having trouble with a function I’m trying to have a function where it displays a notification for the user whenever a new update is posted but whenever I call the function I get this error " Fatal error : Uncaught Error: Call to undefined method mysqli_stmt::fetch_array() in /home/evoarena/public_html/Dev/functions.php:67 Stack trace: #0 /home/evoarena/public_html/Dev/header.php(140): notifications(Object(mysqli)) #1 /home/evoarena/public_html/Dev/login.php(3): require(’/home/evoarena/…’) #2 {main} thrown in /home/evoarena/public_html/Dev/functions.php on line 67"
What am I doing wrong>
Line 67 is
$news_user = $news_stmt->fetch_array();
Function Code:
function notifications($link) {
if (isset($_SESSION['username'])) {
$username = $_SESSION['username'];
$news_query = "SELECT news_read FROM users where username=?";
if ($news_stmt = $link->prepare($news_query)) {
$news_stmt->bind_param("s", $username);
$news_stmt->execute();
$news_result = $news_stmt->get_result();
$news_user = $news_stmt->fetch_array();
if ($news_user['news_read'] == '0') {
echo "<div class='alert alert-primary alert-dismissible' role='alert'>
<center><button type='button' class='close' data-dismiss='alert'>×</button>There is a new post on the <a href='http://www.pereia.net/Dev/news/index.php'>Updates</a> page
</center></div>";
}
} else {
$error = $link->errno . ' ' . $link->error;
echo $error;
}
}
}