I am trying to convert some PHP code for notifications into a more suitable Prepared statement. No matter what I try, it breaks my page. Is any body out there able to tell me where the error lies?
EDIT The page is not completely blank. The page breaks after this code.
$acctNotsQry = $redoDB->prepare('SELECT message, nDate FROM notifications WHERE uID = ? AND nSeen = "0" ORDER BY nDate DESC');
$acctNotsQry->bind_param('i', intval($memID));
$acctNotsQry->execute();
$acctNotsQry->store_result();
$acctNotsQry->bind_result($notMessage, $notnDate);
if($acctNotsQry->num_rows == 0){
echo '<li><div class="nilNots">NO NOTIFICATIONS</div></li>';
} else {
while($acctNotsQry->fetch()) {
?>
<li><i class="fa fa-bell"></i> <?php echo htmlspecialchars_decode(stripslashes($notMessage)); ?>
<p><?php echo date('d M Y - h:ia', strtotime($notnDate)); ?></p></li>
<?php
}
}
$acctNotsQry->close();
SECOND EDIT: The following code DOES work, the above does not. It might help with a solution:
$acctNotsQry = 'SELECT * FROM notifications WHERE uID = "'.$memID.'" AND nSeen = "0" ORDER BY nDate DESC';
$acctNotsRes = $redoDB->query($acctNotsQry);
$acctNotsNum = $acctNotsRes->num_rows;
if($acctNotsNum == 0){
echo '<li><div class="nilNots">NO NOTIFICATIONS</div></li>';
} else {
while($acctNotsRow = $acctNotsRes->fetch_assoc()){
$notMsg = $acctNotsRow['message'];
?>
<li><i class="fa fa-bell"></i> <?php echo htmlspecialchars_decode(stripslashes($notMsg)); ?>
<p><?php echo date('d M Y - h:ia', strtotime($acctNotsRow['nDate'])); ?></p></li>
<?php
}
}
I have tried searching for a solution to no avail. Many thanks in advance.