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.