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 trialtinashegondokondo
Courses Plus Student 13,579 PointsdeleteBook Function Can anyone please assist.
After typing my code I am getting the following:
Bummer! syntax error, unexpected end of file in index.php on line 14
<?php
require __DIR__ . '/inc/bootstrap.php';
//add function here
function deleteBook($bookId) {
global $db;
try {
$stmt = $db->prepare("DELETE from books where id=?);
$stmt->bindParam(1, $bookId);
$stmt->execute();
return true();
} catch (\Exception $e) {
return false;
}
}
1 Answer
Jonathan Grieve
Treehouse Moderator 91,253 PointsHi Tina,
You haven't closed out your string where you make your delete query, so PHP is seeing one big string of characters. Try the following code and it should work.
<?php
require __DIR__ . '/inc/bootstrap.php';
//add function here
function deleteBook($bookId) {
global $db;
try {
$stmt = $db->prepare("DELETE from books where id=?");
$stmt->bindParam(1, $bookId);
$stmt->execute();
return true();
} catch (\Exception $e) {
return false;
}
}
tinashegondokondo
Courses Plus Student 13,579 Pointstinashegondokondo
Courses Plus Student 13,579 PointsThanks Jon.