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 trialPascal Breitrück
Courses Plus Student 3,206 Points@TeamTreeHouse , is empty() the better solution ;D ?
Hey Team,
We use isset() to check if $film set, but we get a bool back and isset(true) and isset(false) will be true :D. If I check the $film with the cool negation operator !empty(true) the condition will be true and with !empty(false) the condition will be false.
<?php
require_once('database.php');
if(!empty($_GET['id'])){
$film_id = intval($_GET['id']);
try {
$results = $db->prepare('select * from film where film_id = ?');
$results->bindParam(1, $film_id);
$results->execute();
} catch(Exception $e) {
echo $e->getMessage();
die();
}
$film = $results->fetch(PDO::FETCH_ASSOC);
/*if($film == FALSE){
echo 'Sorry, a film could not be found with the provided ID.';
die();
}*/
}
?>
<!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>
<?php
if(!empty($film)) {
echo $film['title'];
print_r($film);
}
else {
echo "Sorry film was not found";
}
?>
</h2>
</body>
</html>
how do you think about it . :D
Greets Pascal