Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi,

I am not sure if I understand this right, if I want to use the same template you're using in the book, then the header page completly changes from the code in the download to the code in the book?

 

Here is the code that I put from the book, but it gives me error when I view the site.

 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <title><?php // Use a default page title if one wasn't provided...
 if (isset($page_title)) {
   echo $page_title;
 } else {
   echo 'Virtual Script';
 }
 ?></title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/sticky-footer-navbar.css" rel="stylesheet">

  </head>

  <body>
<?php
   // <!-- Wrap all page content here -->
  

       $page = array (
          'Home' => 'index.php',
          'About' => 'about.php',
          'Contact' => 'contact.php',
          'Register' => 'register.php'
          );
         

      $this_page = basename($_SERVER['PHP_SELF']);
      foreach ($page as $k => $v)  {
           echo '<li';
      if ($this_page = $v) echo ' class="active"';

      echo '><a href="' . $v . '">' . $k . '</a></li>';
} // END OF FOREACH LOOP.

if (isset($_SESSION['user_id'])) {

             echo '<li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">Account <b class="caret"></b></a>
                <ul class="dropdown-menu">
                  <li><a href="logout.php">Logout</a></li>
                  <li><a href="renew.php">Renew</a></li>
                  <li><a href="change_password.php">Change Password</a></li>
                  <li><a href="favorites.php">Favorites</a></li>
                  <li><a href="recommendations.php">Recommendations</a></li>
                </ul>
              </li>';
}

             if(isset($_SESSION['user_admin'])) {
             echo '<li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">Admin <b class="caret"></b></a>
                <ul class="dropdown-menu">
                  <li><a href="add_page.php">Add Page</a></li>
                  <li><a href="add_pdf.php">Add PDF</a></li>
                  <li><a href="#">Something else here</a></li>
                </ul>
              </li>';
         }

?>

          
<?php
$q = 'SELECT * FROM categories ORDER BY categories';
$r = mysqli_query($dbc, $q);
while (list($id, $category) = mysqli_fetch_array($r, MYSQLI_NUM)) {
     echo '<a href="category.php?id=' . $id . '" class="list-group-item="' . $category . '">' . htmlspecialchars($category) . '</a>';
     }
 ?>   
 
<?php
if (!isset($_SESSION['user_id'])) {
require('includes/login_form.inc.php');
}
?>     

<div class="col-9">
<!-- CONTENT -->

</html>

 

 

Thanks very much.

 

 

 

Share this post


Link to post
Share on other sites

Hi,

I fixed the error but the page layout is gone, so I had to reupload the header file, I am trying to get the same template as shown in the book but I can't get rid of the drobdown top menu to make the links appear at the top.
 

Thanks

Share this post


Link to post
Share on other sites

What do you mean by "the page layout is gone"? It might also help if you explained what your URL is and what your directory structure is. 

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...