I'll be honest your code is a bit different to mine so I dunno whats up with that. Here's some edited snippets of my code from emeraldchapter.dyndns.org . Just forget the function line. The $authorized is makes sure your logged in as an admin.
/ Add News /function addNews() {
// Check if user is authorized (login.php) //
$authorized=$_SESSION['auth'];
// Get Data From Form //
$title=$_POST['title'];
$time=date("F j, Y, g:i a");
$poster=$_POST['poster'];
$article=$_POST['article'];
if($authorized==1) { // If your logged in //
$query="INSERT INTO news VALUES ('','$title','$time','$poster','$article')";
mysql_query($query);
header('Location: index.php');
} else {
header('Location: login.php');
}
}
/ Show News /function showNews() {
$query="SELECT * FROM news ORDER BY id DESC";
$result=mysql_query($query);
$rows=mysql_num_rows($result);
$i=0;
while($i<$rows) {
$title=mysql_result($result,$i,'title');
$time=mysql_result($result,$i,'time');
$poster=mysql_result($result,$i,'poster');
$article=mysql_result($result,$i,'article');
echo "<br><b>$title</b><br><i>Written on $time by $poster</i><br> $article<hr>";
$i=$i+1;
}
}
FYI the way I have it is where all the sites content is in one main file and all the pages the site uses just use functions, which makes it easy to edit. If you want you can do this by storing those two things in a file called functions.php and then having the following code on a different page --
<?
/ Include the functions.php file /include('functions.php');
/ Call the function /showNews();
?>
The result of that page is whatever is between the brackets of the function...
function showNews() {
/ All code here is run /}
Yeah I kind went a little far there... Hopefully its a little understandable