Search
Left Quote    Black holes are where God divided by zero.
- Steven Wright    
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 site.inc.php 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.

Validate

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.

Query


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 »


Comments:

  asim13june
  Subject: "Fatal error: Cannot redeclare db_lo..." Date: Nov 02 2007 at 11:35 am    
Hi,
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 e.inc.php:14) in C:\wamp\www\ news\site\sit e.inc.php on line 21].
i have made all php file diffrent. and index files have the include function.
  s141797
  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 site.inc.php works fine...


<?
require_once(& quot;../site/si te.inc.php&quo 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">
</form>
<?

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


Tutorial Stats

Tutorial Stats

538,515 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