Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP & Databases with PDO PDO Queries & Results Query by ID

Trevor Richie
PLUS
Trevor Richie
Courses Plus Student 4,902 Points

404 Error

After following the example in Workspaces, I am still getting a "404 Error" when I click on a movie hyperlink. I can't figure out where my code data is off, I went back through the videos and looked at the final examples that were on screen and I am still getting the error.

<?php

require_once('database.php');

try {
    $results = $db->query('select * from film');
} catch(Exception $e) {
    echo $e->getMessage();
    die();
}

$films = $results->fetchAll(PDO::FETCH_ASSOC);

?>

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">
  <title>PHP Data Objects</title>
  <link rel="stylesheet" href="style.css">

</head>

<body id="home">

  <h1>Sakila Sample Database</h1>

  <h2>Films by Title</h2>

  <ol>
  <?php
    foreach($films as $film){
      echo '<li><i class="lens"></i><a href="films.php?id='.$film["film_id"].'">'.$film["title"].'</li>';
    }

  ?>
  </ol>

</body>

</html>

1 Answer

If you inspect the link that's on the page, does it look how you'd expect?

Also try adding a slash to make sure you're starting at the root of your site:

href="/films....
Trevor Richie
Trevor Richie
Courses Plus Student 4,902 Points

I found the error after about 30 minutes of looking at the Workspaces! Thank you for the help! Make sure you spell things correctly!