PHP MySQL novice to ninja 6th edition delete joke not deleting joke_categories

I have read the entire book and thoroughly enjoyed it. I have coded the examples and am now running the “final website”. My only problem is that when I delete a joke the joke_categories do not get deleted from mysql so the count that shows up on the list is incorrect.

Can you post your code so we can see what the problem might be?

Can you also compare your code to the sample code here: ?

If you visit /category/list you can see a list of categories, and, using the sample code, the delete button removes the category as expected.

Thank you Tom.I have compared my code with the Final-Website and they appear to be equal. The problem is not with adding/deleting categories but with deleting jokes which are assigned to a category. When I delete a joke which is assigned to a category, the joke itself is deleted but not the related items in the joke_category table. If I simply add jokes to the database and do not assign them to a category then everything works as expected.

If you want to tidy up the table, you’ll need to add the relevant delete operation when a joke is deleted $jokeCategoryTable->delete($jokeId) and ensure that the primary key for the $jokeCategoryTable is set to jokeId.

Thank you Tom and thank you to you and Kevin for such a tremendous learning experience with this amazing volume.

1 Like

Thank you for your response but TomB has helped to point me in the right direction. Cheers.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.