Left Quote    Choose a job you love, and you will never have to work a day in your life.
- Confucius    
Right Quote
[login] | [Register]

Building a News Management System

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

Admin Directory

Now need a way to fill the database with information, along with the ability to edit and delete information.

First off create a new folder in your site directory called "admin" or whatever you want. For this purpose, i am using admin as the admin directory.

The code below will call the pre-defined file, and display a form to add a new post:

Notice the code ends with } else { - That's because we still have to process the form once its been submitted. The line: <form action="<? echo $PHP_SELF; ?>" method="POST"> tells the browser that once the submit button has been pressed we can start to process the form contents using the next lot of code.


This peice will check for errors and validate the text input fields contained in the form:

There we just checked that the user has submitted the correct information in the forms.


Next part of code will login to the database, then generate and execute the query to insert the information:

The above code snippets all together will present the user with a form, once all the fields have been validated after submission the contents of the form are sent to the relevant parts of the database. the insertion to the date field is defined in the sql query as NOW() this inserts a current timestamp into to database as opposed to writing in the date and time by hand.

Save the above as add.php in the admin directory.

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


  Subject: "Fatal error: Cannot redeclare db_lo..." Date: Nov 02 2007 at 11:35 am    
can you please help me out of this situtaion..... i have configured everything as said by you..... but im getting a error : [Fatal error: Cannot redeclare db_login() (previously declared in C:\wamp\www\ news\site\sit in C:\wamp\www\ news\site\sit on line 21].
i have made all php file diffrent. and index files have the include function.
  Subject: "Problem help?" Date: Nov 16 2008 at 11:01 am    
When i simply copy paste the script i get a problem...
Looks like the: if (!$submit), is true everytime even when i hit the submit button... Any ideas? The works fine...

require_once(& quot;../site/si t;); //Calls in the previous file we created

// form not yet submitted
// display initial form
if (!$submit)


Add New Post<br />
<form action="& lt;? echo $PHP_SELF; ?>" method="P OST">< br /> <input type="hid den" name="id " value="id ">
Title:<br />
<input size="50 " maxlength=&quo t;60" type="tex t" name="tit le">&l t;br />

News Content:<br />
<textarea name="con tent" cols="40 " rows="10 "> </textarea&g t; <br />
Author:<br />
<input size="50 " maxlength=&quo t;250" type="tex t" name="aut hor"> <br />
<input type="Sub mit" name="sub mit" value="Up date">

} else {
You Must be logged in or a member to comment.

Tutorial Stats

Tutorial Stats

6 Total Comments
0 Rating of 5 ( Votes)


Tutorial Options

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



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

"" Copyright © 2002-2020; All rights lefted, all lefts righted.
Privacy Policy