If we want to edit or delete any of the posts we have submitted, were going to need an admin list of all the posts entered with links to either edit or delete that post.
The below code is the complete code for the admin list page (/admin/list.php):
Its not very pretty, but it displays all the latest posts in descending order, and presents two links next to each title to either edit or delete the post.
the code: <a href='ed.php?id=$send->id'></a> basically calls the edit script into play, while sending the "id" variable with the link. This allows us to edit or delete the post where id=xx.
Edit
The next bit of code is quite like the initial add script that we wrote earlier in the tutorial It connects to the databse and selects the record requested. So if you press edit on id 1, we see a form filled with all the information saved in the first news post.
The edit script - save as (/admin/ed.php):
There we logged into the database and collected all information on id number xx, then displayed the information in a form ready for editing. Next, we need to check if the form has been submitted, and were there any errors? If not, update the record in the db with the new values or halt if any error encountered.
That updated the databse for id number xx with the new values entered into the form.
Delete
And finally, the admin needs to delete posts. this page is only a few lines of code:
With the code sample shown above, we have connected to the database and asked it to delete the article with id number xx.