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

SQLSTATE[HY000]: General error: 1 no such column: film_id2

Getting an error I cant explain any help pleas.

<?php
require('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_id'.$film["film_id"].'">' .$film["title"]. '</a></li>';
    }

    ?>
  </ol>

</body>

</html>

Thank you.

Hey Amadeo,

Your results are push the to the $films variable. In your html you have $film["film_id"]. So just add a s to film and it should work.

1 Answer

In your "href" you wrong after id=

Now you have :

href="films.php?id=film_id'.$film["film_id"].'"

and after GET you will have: "film_id2"

You have to change it with:

href="films.php?id='.$film["film_id"].'"

and after GET you will have: 2