Build Your Own DatabaseDriven Website Using PHP amp;amp; MySQL [Electronic resources]

Kevin Yank

نسخه متنی -صفحه : 190/ 42
نمايش فراداده

A Challenge

As homework, see if you can figure out how to put a link labelled "Delete this Joke" next to each joke on the page that, when clicked, will remove that joke from the database and display the updated joke list. Here are a few hints to get you started:

  • You'll still be able to do it all in a single multipurpose page.

  • You'll need to use the SQL DELETE command, which we learned about in "Getting Started with MySQL".

  • This is the tough one. To delete a particular joke, you'll need to be able to identify it uniquely. The ID column in the Jokes table was designed to serve this purpose. You're going to have to pass the ID of the joke to be deleted with the request to delete a joke. The query string of the "Delete this Joke" link is a perfect place to put this value.

If you think you have the answer, or if you'd just like to see the solution, turn the page. Good luck!