Jump to content

mysqli query doesn't return any data


achilles1971

Recommended Posts

I am working through a php CMS tutorial and I can't get my data to display.  It's like my variable ($pg) is invisible.  If I uncomment the first include in the content div, I get an error that content/.php can't be found (notice the missing file name).  I am passing the values of home, blog, contact and gallery through the URL.  I have home.php, blog.php, contact.php and gallery.php in a folder called content.  Each of the files contains lorem ipsum text and that's all.  I have added an error check and I get no errors...just an empty div.

 

My code is as follows:

 

 

<?php
// Setup document:
include ('config/setup.php');
//---------------------------------------------------
 
//Check if page variable is set
if ($_GET['page']='') {
 
$pg = 'home';
 
}else{
 
$pg = $_GET['page'];
 
}
//---------------------------------------------------
?>
 
 
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Dynamic Sites LLC</title>
<link rel="stylesheet" type="text/css" href="css/styles.css">
 
 
</head>
 
<body>
 
    <div class="header temp_block">
        <?php include ('template/header.php');?>
    </div>
    <div class="nav_main temp_block">
        <?php include ('template/nav_main.php');?>
    </div>
    <div class="content temp_block">       
        <?php //include ('content/' . $pg . '.php');
 
// database connection, query
$q = "SELECT * FROM pages WHERE name = '$pg' AND status = 1 LIMIT 1";
$r = mysqli_query($dbc, $q);
 
$page = mysqli_fetch_assoc($r);
 
echo '<h1>'.$page['title'].'</h1>';
echo '<div class="content_body">'.$page['body'].'</div>';
?>
    </div>
    <div class="footer temp_block">
      <?php include ('template/footer.php');?>   
    </div>
 
 
</body>
</html>
 
My nav_main.php is as follows:
 
<?php
## Main Navigation
 
 
 
 
?>
 
 <a href="index.php?page=home">Home</a> - 
 <a href="index.php?page=gallery">Gallery</a> - 
 <a href="index.php?page=blog">Blog</a> - 
 <a href="index.php?page=contact">Contact Us</a>
 
Any help would be appreciated.
 
Aaron

 

Link to comment
https://forums.phpfreaks.com/topic/275421-mysqli-query-doesnt-return-any-data/
Share on other sites

OK, I changed it to the following:

 

if (isset($_GET['page'])) {
  
  $pg = $_GET['page']; 
  
 }else{  
  
  $pg = 'home';
  
 }

 

Now I get two unidentified index errors in the following lines;

echo '<h1>'.$page['title'].'</h1>';
   echo '<div class="content_body">'.$page['body'].'</div>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.