Data from database not visible on page


#1

Hi everyone,

I’m creating my own little blog system. My blog system will be very easy, just some posts on the page with no admin panel etc. I cannot get the results from the database on my page, is this something that is not possible with a free infinityfree account? I’m using this code:

include “includes/db.php”;

$query = “SELECT * FROM blog_posts”;

$posts = mysqli_query($conn, $query);

if (mysqli_num_rows($posts) > 0) {
while ($row = mysqli_fetch_assoc($posts)) {
echo $row[‘post_title’];
// And all the other rows…
}
}


#2

This should be general question, and I don’t think that InfinityFree limit the query execution.

Double check your credential at variable $conn and your database too.


#3

A database which can’t execute a simple SELECT query would be completely useless, so that’s probably not the issue here.

As I see it, I suspect the problem is either:

  • The table you’re querying is in fact empty and not returning any rows.
  • The query is returning an error which flew under the radar.

Your code snippet is a bit short, but I don’t see any error checking codes in there. Try checking whether the connection was successful and whether the query returned any errors:

http://php.net/manual/en/mysqli.error.php
http://php.net/manual/en/mysqli.connect-error.php

Also, try running this query from phpMyAdmin to see whether you get back any results.


closed #4