Jump to content

companyhome.php error


dlinden

Recommended Posts

I have an error I can’t resolve…

 

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in /home5/camfulco/public_html/CompanyHome.php on line 132

 

<?php
  /* Program: CompanyHome.php
   * Desc:    Displays a Web page that has four levels:
   *          1) the home page, 2) a department page, 3) a
   *          content list page, and 4) a detail page.
   */
if (!isset($_SESSION))                                   #7
  session_start();

include_once("functions_main.inc");

$page = array(                                           #12
  "title"          => "The Company Intranet",
  "header"         => "The Company Intranet",
  "bottom"         => "Copyright(R) 2005",
  "left_nav_links" => array(),
  "body_links"     => array(),
  "col_headers"    => array(),
  "data_rows"      => array(),
);

$admin = FALSE;
$base_url = "CompanyHome.php";
$trail = "<a href='$base_url'>Home</a>";                #24

if (!isset($_SESSION['user_name']))
  header("Location: Login.php");                        #27
else
{
  if (isset($_SESSION['user_dept'])
      && isset($_GET['dept_id']))
  {                                                     #32
    $admin = $_SESSION['user_dept'] == $_GET['dept_id'];
  }

  $cxn = Connect_to_db("Vars.inc");
  $left_nav_links = array();
  $page["browse_level"] =                               #38
    isset($_GET['browse_level']) ?
      $_GET['browse_level'] : "home";               

  switch ($page["browse_level"])                        #42
  {
    case "home":
      $sql = "SELECT name, dept_id, description
              FROM Department
              ORDER BY name";
      $results = mysqli_query($cxn, $sql);
      $body_links = "";
      while($row = mysqli_fetch_assoc($results))        #50
      {
        $link = "$base_url?dept_id=" . $row['dept_id']
          . "&browse_level=department";
        $page["left_nav_links"][$link] = $row['name'];
        $body_links .= "<li><a href=\"" . $link
          . "\">" . $row['name'] . "</a> - "
          . $row['description'];
      }
      $page["left_nav_header"] = "Departments";         #59
      $page["top"] = "Welcome to our Intranet";
      $page["body_text"] = "Welcome to our Intranet "
        . "where each department shares content with "
        . "the whole company.  You can update your "
        . "own departments content too with our simple "
        . "interface.<p>Vist the departments' "
        . "home pages: $body_links";

      break;

    case "department":                                  #70
      $dept_id = $_GET['dept_id'];
      $sql = "SELECT name, dept_id, description
              FROM Department
              WHERE dept_id = $dept_id ORDER BY name";
      $results = mysqli_query($cxn, $sql);
      $row = mysqli_fetch_assoc($results);
      $dept_name = $row['name'];
      $dept_desc= $row['description'];

      $page["left_nav"] = "$dept_name Content";
      $page["body_text"] = "$dept_name - $dept_desc";
      $sql = "SELECT a.name, a.type_id,
                     count(b.content_id)
              FROM Content_Type a
              LEFT OUTER JOIN Content b on
                   a.type_id = b.content_type
                   and b.dept_id = $dept_id
              GROUP BY a.name, a.type_id ORDER BY name";
      $results = mysqli_query($cxn, $sql);

      $body_links = "";
      while($row = mysqli_fetch_assoc($results))        #92
      {
        $link = "$base_url?dept_id=$dept_id"
          . "&type_id=" . $row['type_id']
          . "&browse_level=content";
        $page["left_nav_links"][$link] = $row['name'];
        $body_links .= "<li><a href=\"" . $link
          . "\">" . $row['name'] . "</a>";
      }
      $page["left_nav_header"] = "Content Index";
      $page["top"] = $dept_name;
      $page["body_text"] = "$dept_name - $dept_desc "
        . "<p>Vist the departments' "
        . "areas: $body_links";
      $trail .= " - <a href='$base_url?dept_id=$dept_id"
             .  "&browse_level=department'>$dept_name</a>";
      break;

    case "content":                                    #110
      $dept_id = $_GET['dept_id'];
      $type_id = $_GET['type_id'];
      $sql = "SELECT a.name, a.type_id, b.title,
                b.description, b.content_date,
                b.create_date, b.created_by,
                b.last_upd_date, b.last_upd_by,
                c.name as dept_name, content_id
              FROM Content_Type a, Department c
              LEFT OUTER JOIN Content b on
                a.type_id = b.content_type
                and a.type_id = b.content_type
                and b.dept_id = $dept_id
                and b.content_type = $type_id
              WHERE c.dept_id = $dept_id
              ORDER BY content_date DESC";
      $results = mysqli_query($cxn, $sql);

      $body_links = "";
      $content_count = 0;
      $page["body_text"] = "";

      while($row = mysqli_fetch_assoc($results))       #132
      {
        if (!isset($area_name) && $type_id == $row["type_id"])
        {
          $area_name = $row["name"];
          $dept_name = $row["dept_name"];
        }
        $link = "$base_url?dept_id=$dept_id"
          . "&type_id=" . $row['type_id']
          . "&browse_level=content";
        $page["left_nav_links"][$link] = $row['name'];

        if (!isset($row["content_id"]))               #144
          continue;

        $content_id = $row["content_id"];

        $content_count++;
        $link = "$base_url?dept_id=$dept_id"
          . "&type_id=$type_id&browse_level=content";
        $page["left_nav_links"][$link] = $row['name'];
        $page["data_rows"][] = $row;

      }
      if ($content_count == 0)                         #156
      {
        $page["body_text"] = "There are no $area_name
          content items for $dept_name";
      }
      if ($admin)                                      #161
      {
        $page["body_text"] .= "<p>[<a href='$base_url?dept_id=$dept_id"
               . "&browse_level=details&type_id=$type_id"
               . "&content_id='>add</a>]";
      }
      $page["col_headers"]["title"] = "$area_name Title";
      $page["col_headers"]["content_date"] = "$area_name Date";
      $page["col_headers"]["create_date"] = "Created On";
      $page["col_headers"]["created_by"] = "Created By";
      $page["col_headers"]["last_upd_date"] =
        "Last Updated On";
      $page["col_headers"]["last_upd_by"] =
        "Last Updated By";

      $page["left_nav_header"] = "Content";            #176
      $page["top"] = "$dept_name - $area_name";
      $trail .= " - <a href='$base_url?dept_id=$dept_id"
             .  "&browse_level=department'>$dept_name</a>";
      $trail .= " - <a href='$base_url?dept_id=$dept_id"
             .  "&browse_level=content"
             .  "&type_id=$type_id'>$area_name</a>";
      break;

    case "details":                                    #185
      $dept_id = $_GET['dept_id'];
      $type_id = $_GET['type_id'];

      $sql = "SELECT a.name as dept_name, b.name
              FROM Department a, Content_Type b
              WHERE b.type_id = $type_id
                and a.dept_id = $dept_id
              ORDER BY name";
      $results = mysqli_query($cxn, $sql);
      $body_links = "";
      $content_count = 0;

      while($row = mysqli_fetch_assoc($results))       #198
      {
        $area_name = $row["name"];
        $dept_name = $row["dept_name"];

        if (!isset($row["content_id"]))                #203
          continue;

        $content_count++;
        $link = "$base_url?dept_id=$dept_id"
          . "&type_id=".$row['type_id']
          . "&browse_level=content";
        $page["left_nav_links"][$link] = $row['name'];
        $body_links .= "<li><a href=\"" . $link
          . "\">" . $row['name'] . "</a>";
      }
      $create_date = date("m/d/y", time());
      $created_by = $_SESSION["user_name"];
      $last_upd_by = $_SESSION["user_name"];

      $content_id = $_GET["content_id"];
      $edit = $admin && (@$_GET["edit"] == "true"
                         || $content_id == "");

      if ($content_id != "")                           #222
      {
        Connect_to_db("Vars.inc");
        $sql = "SELECT content_id, dept_id, content_date,
                  content_type as type_id, title,
                  description, create_date,
                  created_by, last_upd_date, last_upd_by
                FROM Content
                WHERE content_id = $content_id";
        $results = mysqli_query($cxn, $sql);
        if ($row = mysqli_fetch_assoc($results))
        {
          foreach ($row as $key => $value)
            $$key = $value;
        }
        $sql = "SELECT download_id, file_name
                FROM Content_Download
                WHERE content_id = $content_id";

        $results = mysqli_query($cxn, $sql);
        while($row = mysqli_fetch_assoc($results))     #242
        {
          $download_id = $row["download_id"];
          $file_name = $row["file_name"];
          $link = "files/$download_id/$file_name";
          $page["left_nav_links"][$link] = $file_name;

          if ($edit)                                   #249
            $page["left_nav_links"][$link] .= "</a>
            [<a href=\"Admin.php"
              . "?action=DeleteDownload&download_id=$download_id\"
            >del</a>]";
        }
      }

      foreach ($_GET as $name => $value)               #257
        $$name = $value;

      $edit = $admin && (@$_GET["edit"] == "true" || $content_id == "");

      $page["top"] = "$dept_name - $area_name";

      if ($edit)                                       #264
      {
        $page["body_text"] = "<center><u>Add Downloads</u>";
        for ($i = 0; $i < 3; $i++)
        {
          $page["body_text"] .=
            "<br><input type='file' name='upload_file$i'>";
        }

        $page["body_text"] .= "
          </center> <p />
          <center>
            <input type='reset' name='action'
              value ='Reset Form'>
            <input type='submit' name='action'
              value ='Cancel'>
            <input type='submit' name='action'
              value ='Save Changes'>
          </center>";

        $page["top"] .= " Edit/Create";
      }
      else
      {
        $page["body_text"] =
          "<a href='javascript:history.go(-1)'>Back</a>";
      }

      $page["left_nav_header"] = "Downloads";
      $trail .= " - <a href='$base_url?dept_id=$dept_id"
             .  "&browse_level=department'>$dept_name</a>";
      $trail .= " - <a href='$base_url?dept_id=$dept_id"
             .  "&browse_level=content"
             .  "&type_id=$type_id'>$area_name</a>";

      break;
  }

  include("company.inc");
}
?>

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.