What I like to do is start a session at the top of a page.
<?php
session_start();
?>
If the form is submitted, user input sanitized, and inserted into DB, I create a session var:
<?php
// if result
if($result === true)
{
// create a session var
$_SESSION['inserted'] = 1;
}
?>
before you add data, you can check to see if the values were already inserted by testing for the presence of this session
<?php
// if post is set, BUT session var "inserted" isn't
if(isset($_POST) && !isset($_SESSION['inserted']))
{
// insert data...
}
?>
SO, putting it all together, you could try this:
<?php
// start session
session_start();
// if form has NOTE been submitted
if(!isset($_POST['submit']))
{
// display form
include('form.php');
echo $form;
}
// else the form was submitted, process form:
else {
// if session var set
if(isset($_SESSION['inserted']))
{
echo 'Your data has been saved in the db.';
}
// else insert data after cleansing & sanitizing it
else {
$result = mysql_query($query) or die(mysql_error());
if($result)
{
// set session var
$_SESSION['inserted'] = 1;
// confirm to user
echo 'you did it, you!';
}
}
}
?>
this is just the general idea... hope this helps...