T4VN is an online PHP Help community that provides PHP Tutorials, PHP Examples, PHP Scripts, PHP Support
    HOME  |  HOSTING COUPON  |  TEMPLATE  |  PHP SCRIPTS  |  LINK TO US  |  LINK  |  REGISTER | CONTACT
::: Member Login :::
 Username
 Password
 
Forgot your password ?
::: PHP Tutotal :::
  PHP Basic (7)
  PHP Advanced (4)
  PHP Database (2)
  Coding Step By Step (8)
  PHP and AJAX (0)
::: PHP Example :::
  Arrays (1)
  Code Highlighters (3)
  Database Functions (12)
  Date & Time (5)
  E-Mail (6)
  Forms (5)
  Guestbooks (1)
  Logging (2)
  Miscellaneous (10)
  Password Generators (3)
  Randomizers (3)
  String Manipulation (10)
  User Authentication (6)
::: Search On T4VN :::
::: T4VN Statistics :::
  PHP Scripts : 61
  PHP Example : 67
  PHP Tutorials : 21
  PHP News : 93
  Total Coupon : 36
  Other Tutorials :
  Member : 200
  Visitor Online : 2
  Today Visit: 215
  Total Visitor : 229492
  Most Online : 31
::: Sponsored Links :::

PR 4 For This Webpage
Home Today :

Create Simple News System


This news system is easy to set up, and very easy to use. It even has an admin area so it makes it easy for your moderators or news reporters to post. Once it is set up, it requires no special knowledge to post news.

Before we begin, we should set up a table in our mysql database. We will need to following fields:
Name
Subject
Message
Date
ID


The first thing to do, after setting up the database, is create the administrator area where all the posting will occure. You can name this whatever you want, but we will refer to it as newsposter.php in this example. Now place the following code in this file:

PHP Tutorials :

<?
$db_host 
"localhost";
$db_username "your_db_username";
$db_password "your_db_password";
$db_name "your_db_name";

if (
$submit) {
mysql_connect($db_host,$db_username,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());

$date date("D m/d/Y - g:ia");

$query "INSERT INTO news (name, subject, message, date)
VALUES ('$name','$subject','$message','$date')"
;
mysql_query($query);

mysql_close();

echo 
"Thanks $name your message has been added";
}

?>
<form name="news" method="post" action="<? echo $PHP_SELF ?>">
<table align="center" cellpadding="6" cellspacing="0">
<tr>
  <td>Name :</td>
  <td><input type="text" name="name"></td>
</tr>
<tr>
  <td>Subject :</td>
  <td><input type="text" name="subject"></td>
</tr>
<tr>
  <td valign="top">Message :</td>
  <td><textarea name="message" cols="30" rows="6"></textarea></td>
</tr>
<tr>
 <td> </td>
  <td><input type="submit" name="submit" value="Add" style="cursor:pointer"> <input type="reset" name="reset" value="Clear" style="cursor:pointer"></td>
</tr>
</table>
</form>


Now save that file in a directory of your choice and start a new file. Name this file, either news.php or you can place the code into your index file and have the news displayed on your index page, and put the code in it.

PHP Tutorials :

<?

$db_host 
"localhost";
$db_username "your_db_username";
$db_password "your_db_password";
$db_name "your_db_name";

mysql_connect($db_host,$db_username,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());

$query "SELECT name, subject, message, date
FROM news order by date DESC"
;
$result mysql_query($query);

echo 
"<br><center>";

while(
$r=mysql_fetch_array($result))
{

echo 
"<tr>";
echo 
"<td bgcolor='#FFFFFF'><h10>// $r[subject]<HR color='#660000'></td>";
echo 
"</tr>";
echo 
"<tr>";
echo 
"<td bgcolor='#FFFFFF'>$r[message]<HR color='#660000'></h10></td>";
echo 
"</tr>";
echo 
"<tr>";
echo 
"<td bgcolor='#FFFFFF'>Posted By:
$r[name]</a>   $r[date]<br><br><br></td>"
;
echo 
"</tr>";
}
echo 
"</table>";

?>



You're done.

Author by steelmanronald06

Other Tutorials
Simple Upload Page
Create Simple ShoutBox
Sending Simple Text Emails
Simple Hit Counter
Building a Counter

::: Resources :::
  Links Directory
  Programming 2 3
  Webmaster 2 3
  Web Design 2 3
  Web Hosting 2 3
  Other Links 2 3
  Asian ShowBiz News
  Teach Seo For You
::: New Templates :::




::: Other Tutorials :::
 Program Design

  Powered By T4VN.NET - Version 2.0 - CopyRight © T4VN.NET 2005-2007