Thanks for the quick reply NEVERMIND but as I said I am new to php and I couldn't get it working it still Reposts when the user clicks Refresh. The active cut down code below is at:
www.mnmnt.id.au/test/test.html
the real guest book is at :
www.mnmnt.id.au/BFVPB/BFVPB.html
Following is a cut down version of the code, I have put remarks where I tried things I also tried
header("Location: $_SERVER[PHP_SELF]?$_SERVER[QUERY_STRING]"); :
after the include statement from my html
THANKS AGAIN
<?
if ( isset( $test_data ) && $test_data <> "already posted")
//
{
// check user input here!
$dberror = "";
$ret = add_to_database( $test_data, $dberror );
if ( ! $ret )
print "Error: $dberror<BR>";
else
display();
print "<center>Thank's for your feedback<br><br></center>";
// I tried setting $test_data to "already posted" then using adding an if statement under the isset function
//$test_data = "already posted"
// unset(test_data)
// unset($globals['test_data'])
// session_destroy()
write_form();
}
else {
display();
write_form();
}
function add_to_database( $test_data, &$dberror )
{
$user = "MY USER NAME";
$pass = "MY PASSWORD";
$db = "MY DATABASE";
$link = mysql_pconnect( "localhost", $user, $pass );
if ( ! $link )
{
$dberror = "Couldn't connect to MySQL server";
return false;
}
if ( ! mysql_select_db( $db, $link ) )
{
$dberror = mysql_error();
return false;
}
$query = "INSERT INTO test ( t1 )
values( '$test_data' )";
// header("Location: $_SERVER[PHP_SELF]?$_SERVER[QUERY_STRING]");
// unset(test_data)
// unset($globals['test_data'])
// session_destroy()
if ( ! mysql_query( $query, $link ) )
{
$dberror = mysql_error();
return false;
}
return true;
}
function write_form()
{
print "<center><table width=30%><tr><td width=100% height=\"50\">";
global $PHP_SELF;
print "<form action=\"$PHP_SELF\" method=\"POST\">\n";
print "Test data\n";
print "<input type=\"text\" name=\"test_data\">\n";
print "<br>";
print "<input type=\"submit\" value=\"submit!\">\n</form>\n";
print "</td></tr></table></center>";
}
function display()
{
$user = "MY USERNAME";
$pass = "MY PASSWORD";
$db = "MY DATABASE";
$link = mysql_connect( "localhost", $user, $pass );
if ( ! $link )
die( "Couldn't connect to MySQL" );
mysql_select_db( $db, $link )
or die ( "Couldn't open $db: ".mysql_error() );
$result = mysql_query( "SELECT * FROM test" );
$num_rows = mysql_num_rows( $result );
print "<center>\n";
while ( $a_row = mysql_fetch_row( $result ) )
{
print "<table border=1 width=70%>\n";
print "<tr><td>\n";
print "$a_row[0]";
print "</td></tr>\n";
print "</table>\n";
print "<br>\n";
}
print "</center>\n";
mysql_close( $link );
}
?>