Hi guys. I give up... I can't seem to make deletejoke.php work using the code shown in the book.
My "try" block of deletejoke.php looks like this:
$pdo = new PDO('mysql:host=localhost;dbname=ijdb;charset=utf8', 'ijdbuser', 'P@ssw0rd'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = 'DELETE FROM `joke` WHERE `id` = :id'; $stmt = $pdo->prepare($sql); $stmt->bindValue(':id', $_POST['id']); $stmt->execute(); header('location: jokes.php');
Page displays fine, I have all the jokes visible, just Delete button doesn't work. Browser seems to do something for less than a second (page does not reload) but still displays same jokes, so nothing gets deleted.
I tried to test it step by step and think the issue is with "bindValue" line.
For example, if I update SQL query to: $sql = 'DELETE FROM
id = 5' and comment out the bindValue line, if I will press Delete button on any joke line, joke with ID = 5 will be successfully deleted.
Is my issue with :id or with entire bindValue line?