SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2013
    Posts
    35
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    PHP and MySQL: Novice to Ninja - Chapter Six totaljokes-function

    I'm not able to get this example to work. Here is my code for totalfilms-function.inc.php where titles = the name of a table in my db:
    PHP Code:
    <?php
    include_once $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
    function 
    totalFilms()
    {
        
    try {
    $result $GLOBALS['pdo']->query('SELECT COUNT(*) FROM titles');
      }
      catch (
    PDOException $e)
      {
        
    $error 'Database error counting films!';
        include 
    'error.html.php';
        exit();
    }
      
    $row $result->fetch();
      return 
    $row[0];
    }
    The only other file I have in the totalfilms directory is error.html.php. When I load up the directory this is what I get:
    Screen Shot 2013-11-02 at 10.39.09 AM.png
    It seems I need another file to display the result of the totalfilms function but I'm not sure how to write it.
    Attached Images Attached Images

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    I guess your index.php is missing. Are you sure in the book there isn't another part of the example?

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2013
    Posts
    35
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    I guess your index.php is missing. Are you sure in the book there isn't another part of the example?
    Thanks! The book doesn't mention it but the missing files are included in the code archive.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •