php - MYSQLI Prepared Statement White Page -
i trying convert php code notifications more suitable prepared statement. no matter try, breaks page. body out there able tell me error lies?
edit page not blank. page breaks after code.
$acctnotsqry = $redodb->prepare('select message, ndate notifications uid = ? , nseen = "0" order 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: following code work, above not. might solution:
$acctnotsqry = 'select * notifications uid = "'.$memid.'" , nseen = "0" order 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 solution no avail. many in advance.
change
$acctnotsqry->bind_param('i', intval($memid));
to
$acctnotsqry->bind_param('i', $memid);
the 2nd , following arguments bind_param
reference parameters, have use variables there, not expressions. don't need call intval()
yourself, i
type in first argument tells mysqli convert integer when sending mysql.
Comments
Post a Comment