Building a Data-Driven Website / Deleting a Post or Thread
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
The kill.php script is a script that as I mentioned at the end of last movie is called when the user either wants to delete one of their own posts or they’re a moderator and they want to delete a post be it belonging to them or someone else or it could even be a whole thread. First of all the kill.php script starts a session, installs the functions that are stored within forum.inc and then test it to make sure the user is logged in, if they are, then we connect to the database and at this point the scripts branches because there are two different paths that could be followed, first of which is if it's a post that the script is being called on to delete in which case it's a simple matter of issuing an S.Q.L query that deletes that one particular post with that post i.d and since the post id is a unique primary key field, we can be sure that we’re only deleting that one post. If however, it's a thread that the script is being called on to delete, then there is an extra step to be carried out. First of all, the thread has to be deleted using a mysql query and then the posts that make up the thread also have to be deleted to save space on the database and to fully execute the action of deleting a thread even though they be inaccessible there’s no point of deleting a thread if they’re not saving the space. If however neither variable is being specified, then the page must have been reached by accident somehow and so error message is given and the user is bounced back to the main page. In main.php I’ve added this Java script as part of the html that's echoed to the browser within a table and this piece of Java script is set to an event on the delete hyperlink, which is right next to each of the threads on the main page if the user is logged as a moderator. This works in a very similar way to the Java script that is served up by post.php. However this time the name of the user, the logged in user is included as part of the Java script, so that when in our browser we go to delete one of the threads, the java script prompt actually uses the name. Now let’s take a quick look at the source of this page, if we look right down to where the Java script is written, as we can see, there is nothing magic about this. The reason that Java script knew the registered session variable is that its part of the whole page that has been posted to the browser by the server. This is another example of the ways in which client side and server side scripting can work together in harmony, very similarly to what we’re using on post.php page. So that sums up the kill.php script and the whole of this final project and therefore the whole of this title php. I hope you find it useful and that you continue to use php and learn more about php and hopefully that at some point, you find yourself in a position where you can give back to the php community whether this be through contributing to the open source project that is the on going creation of php or whether its simply by the shining examples that will you create of good php scripts.
Tutorial Information
| Course: | PHP |
| Author: | Joshua Mostafa |
| SKU: | 33332 |
| ISBN: | 1889347787 |
| Release Date: | 2002-03-26 |
| Duration: | 9.5 hrs / 92 lessons |
| Work Files: |
Yes |
| Captions: | For Online University members only |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 