You can make page reusable.
<?php
}
else {
//include config file
include "config.php";
// get form input
// check to make sure it's all there
// escape input values for greater safety
$title = empty($_POST['title']) ? die ("ERROR: Enter a title") : mysql_escape_string($_POST['title']);
$author = empty($_POST['author']) ? die ("ERROR: Enter an author") : mysql_escape_string($_POST['author']);
$intro = empty($_POST['intro']) ? die ("ERROR: Enter an intro") : mysql_escape_string($_POST['intro']);
$text = empty($_POST['text']) ? die ("ERROR: Enter the text") : mysql_escape_string($_POST['text']);
$editing = ($_POST['editing'] =='yes');
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
//evaluate added form field to se if editing or new entry
if($editing)
{
// edit query
$query = "
UPDATE news
SET
title='$title',
author='$author',
intro='$intro',
text='$text'
";
}
else
{
// insert query
$query = "
INSERT INTO news
(title, author, intro, text)
VALUES
('$title', '$author', '$intro', '$text')";
}
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// print message with ID of inserted or edited record
echo ($editing
?"New record inserted" : "Record edited")." with ID ".mysql_insert_id();
// close connection
mysql_close($connection);
}
?>