Add News Feature
Posted: Sun Dec 28, 2003 11:20 am
Alright, I have my post.html (html form) and my post.php (php fuctions saving the name and content to my db).
Now that I have the enteries in my db, I would like to post the 5 newest entries on my index.php page in desending order.
Also I would like to have a archives of all of the enteries on a seperate page (Will show all articles, even ones on index.php).
POST.HTML
POST.PHP
Some how on the index.php page I need to get the top 5 article id's from the db, and list them in desending order (from the highest to the lowest).
And the same for the archives page, which will just show all of the articles.
Now that I have the enteries in my db, I would like to post the 5 newest entries on my index.php page in desending order.
Also I would like to have a archives of all of the enteries on a seperate page (Will show all articles, even ones on index.php).
POST.HTML
Code: Select all
<form name="addnews" method="post" action="post.php">
<p class="bodymd">Name<br>
<input type="text" name="name">
</p>
<p class="bodymd">Content<br>
<textarea name="content" rows="10" cols="50"></textarea>
</p>
<p class="bodymd">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Clear Form">
</p>
</form>POST.PHP
Code: Select all
<?php
if (($_POST['name'] == "") || ($_POST['content'] == ""))
{
echo "Invalid Name or Content";
echo "<br>";
echo "<a href='post.html'>Back</a>";
exit;
}
$conn = mysql_connect("localhost","username","password") or die ("Couldn't connect to DB.");
$db = mysql_select_db("db") or die(MySQL_Error()); // change DB to your database name..
$sql = "INSERT INTO news (id, name, content)". "VALUES ('NULL', '".$_POST['name']."', '".$_POST['content']."')";
$result=MySQL_Query($sql) or die(MySQL_Error());
{
echo "<b>Your Content Was Added</b>";
echo "<br>";
echo "Name: ";
echo $_POST['name'];
echo "<br>";
echo "Content: ";
echo $_POST['content'];
}
?>And the same for the archives page, which will just show all of the articles.