Search
Left Quote    Nearly all men can stand adversity, but if you want to test a man's character, give him power.
- Abraham Lincoln    
Right Quote
 
[login] | [Register]
 

Building a News Management System

by: sm0ke
Page: 3 of 5
(View All)

Admin Features

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.


1  |  2  |  3  |  4  |  5  |  
Next »


Comments:

  s141797
  Subject: "Problem help" Date: Nov 16 2008 at 10:31 am    
I am having a problem at the del.php page.

This sentence does not work: $query = "DELETE FROM news WHERE id = '$id'"; .... Its like my script does not recieve the id or something, I get no error message but the row does not get deleted from my table.

If i use this: $query = "DELETE FROM news WHERE id = '1'"; the row gets deleted from the table but then the entire of the script is gone.

Im having the same problem at the r.php file.... This site just returns nothing.

I have simply copy pasted all the code in the tutorial and changed the db login variables.

Any ideas?
You Must be logged in or a member to comment.


Tutorial Stats

Tutorial Stats

541,201 Views
6 Total Comments
0 Rating of 5 ( Votes)

Options

Tutorial Options

· Login to Rate This Article
· Login to Post a Comment
· Read more by this author
Digg This Article! Del.icio.us: Bookmark This Article Reddit: Bookmark This Article BlinkList: Blink This Article! YahooMyWeb BlogMarks: Add This Mark! Furl: Save This Article Spurl: Mark This Article

Articles

Related    

· Simple PHP Tutorial
· One File Website
· Pagination with PHP
· Building a Comments Script
· Complete Members System
· Variable Scope



"AllSyntax.com" Copyright © 2002-2017; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank