0

I want to fetch data from the database by using a prepared statement but it failed and not even showing any error. I used this but still not working $result15->close(); Help me to write this code.

<?php
    $prep_stmt = "SELECT id  FROM detail WHERE id = ?  LIMIT 10";
    $result15 = $mysqli->prepare($prep_stmt);
    $result15->bind_param("i",$id);
    $result15->execute();
    $row151=$result15->get_result();
?>

               
<?php
  while($res15 = $row151->fetch_assoc()){
?>
<tr>
<td><a href="post?id=<?php echo  base64_encode(urlencode($res15->id))?>&<?php echo $res15->addpage;?>" target="_blank"><?php echo $res15->post_name;?></a></td>
</tr>

<?php
 }
 $result15->close();
?>
  • `$res15->id` should be `$res15['id']` since you used `fetch_assoc()`, not `fetch_obj()`. – Barmar Mar 10 '21 at 18:02
  • And you need to add columns like `addpage` and `post_name` to the `SELECT` statement – Barmar Mar 10 '21 at 18:02
  • 1
    You should be getting "Trying to get property of non-object" warnings from that code. – Barmar Mar 10 '21 at 18:02
  • 1
    Please turn on [PHP](https://stackoverflow.com/a/21429652/231316) and [MySQL](https://stackoverflow.com/a/22662582/231316) error reporting. – Chris Haas Mar 10 '21 at 18:05
  • what is the value of `$id`? Your code doesn't show this value as being set – Martin Mar 10 '21 at 18:07
  • @ChrisHaas It may be better to encourage the OP to [**output their errors to the log file**](https://stackoverflow.com/questions/5127838/where-does-php-store-the-error-log-php5-apache-fastcgi-cpanel) rather than to screen `;-)` – Martin Mar 10 '21 at 18:08
  • @Barmar I used this but didn't work $res15['id'] – Rishabh Raj Mar 10 '21 at 18:09
  • Did you set `$id` first? Are you sure there are rows in the table with that ID? – Barmar Mar 10 '21 at 18:10
  • What output are you getting? Are you getting anchors with empty `?id=`, or are you getting no anchors at all? – Barmar Mar 10 '21 at 18:11
  • @Martin, although I agree in general, for development I strongly encourage loud, proud and in-your-face error messages. Log files are great if people actually check them, but people will actually fix "object doesn't support method XYZ" if they see it on a screen! – Chris Haas Mar 10 '21 at 18:12
  • @ChrisHaas are you saying the White Screen of Death doesn't give enough information?! `:-D` . I can see that in a testing enviornment yes it's easier to have it all error data on screen, but I think it's worth noting that error logging is a better way, for the OP to explore that should they wish to `:-)` – Martin Mar 10 '21 at 18:16
  • 1
    @Martin it doesn't really matter as the certain media is not relevant to the question. the code must be written the way that it throws an error. While how this error will be processed is outside of the scope of this code and this question – Your Common Sense Mar 10 '21 at 18:29

0 Answers0