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
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>';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.