Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed PHP User Authentication!
You have completed PHP User Authentication!
Preview
We will learn to modify books from the library by modifying our book form.
Functions.php
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;
}
}
procedures/deleteBook.php
require_once __DIR__ . '/../inc/bootstrap.php';
$book = getBook(request()->get('bookId'));
deleteBook($book['id']);
$response = \Symfony\Component\HttpFoundation\Response::create(null, \Symfony\Component\HttpFoundation\Response::HTTP_FOUND, ['Location' => '/books.php']);
$response->send();
exit;
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
anyone to edit and delete a book.
0:00
But we'll be changing that in a little
bit when we talk about authentication and
0:01
authorization.
0:05
Let's start by opening up
the book.php file in the inc folder.
0:07
We include this file for
each book on our book list page.
0:11
We're going to add two links here.
0:15
Let's start with edit.
0:18
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up