achilles1971 Posted March 8, 2013 Share Posted March 8, 2013 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 8, 2013 Share Posted March 8, 2013 Try checking for SQL errors, see my signature. Quote Link to comment Share on other sites More sharing options...
achilles1971 Posted March 8, 2013 Author Share Posted March 8, 2013 Thanks for the reply, Jessica. The query returns no errors. Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 8, 2013 Share Posted March 8, 2013 Print_r($page); ?? Quote Link to comment Share on other sites More sharing options...
achilles1971 Posted March 9, 2013 Author Share Posted March 9, 2013 Nothing... It's like $pg is not getting passed to the query Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 9, 2013 Share Posted March 9, 2013 Echo the query Quote Link to comment Share on other sites More sharing options...
achilles1971 Posted March 9, 2013 Author Share Posted March 9, 2013 SELECT * FROM `pages` WHERE `NAME` = '' AND `STATUS` = 1 LIMIT 1 That's what I'm talking about...no $pg single quotes after `NAME`= Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 9, 2013 Share Posted March 9, 2013 What's the URL you're visiting? Quote Link to comment Share on other sites More sharing options...
achilles1971 Posted March 9, 2013 Author Share Posted March 9, 2013 localhost on my computer localhost/practice Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 9, 2013 Share Posted March 9, 2013 Well there's no get param. It's not set to '', it just doesn't exist. You need to add a check to see if it is or is not set and default it to "home". Quote Link to comment Share on other sites More sharing options...
achilles1971 Posted March 9, 2013 Author Share Posted March 9, 2013 Isn't that what is happening inside the "check if page variable is set" comment at the top? Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 9, 2013 Share Posted March 9, 2013 No. In fact it's setting it to '' because you used = and not == But if something doesn't exist at all it can't be == '' You need isset() too. Quote Link to comment Share on other sites More sharing options...
achilles1971 Posted March 9, 2013 Author Share Posted March 9, 2013 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>'; Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 9, 2013 Share Posted March 9, 2013 Go back and do all the debugging steps again that I said the first time. Quote Link to comment Share on other sites More sharing options...
achilles1971 Posted March 9, 2013 Author Share Posted March 9, 2013 SUCCESS! You're a peach... Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 9, 2013 Share Posted March 9, 2013 What was the problem? Quote Link to comment Share on other sites More sharing options...
achilles1971 Posted March 9, 2013 Author Share Posted March 9, 2013 SQL was throwing an error because the fields are case sensitive. Since I wasn't using the same case, there was no data. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.