[PHP] Refreshing page after form submission

2004-12-17 Thread S.D.Price

Hi, I have a form which when submitted adds a record to a DB. However if
the user clicks back it resubmits the same record.

I have tried using cache control to no avail :

header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified:" . gmdate("D, d M Y H:i:s"). " GMT");
header ("Cache-control: no-store, no-cache, must revalidate");
header("Cache-control: post-check=0, pre-check=0, false");
header ("Pragma: no-cache");
session_cache_limiter("nocache");

I also tried testing for the presence of a submit button so if the user
enters data submits the form and clicks back the page will refresh.

";
} else { 
} 
?>

The problem is I need to display a confirmation message after the user
submits, and with this technique the page always redisplays the (empty)
form after submission.

Any ideas?



Steve



RE: [PHP] Refreshing page after form submission

2004-12-17 Thread S.D.Price

Thanks this was the best solution I used this code as part of form
validation.

// query to check record has not already been added by comparing
submitted title with title of last record
$query_gnewsid_unique = "SELECT MAX(newsid) AS newsid FROM
tblnews";

// execute query
$result_gnewsid_unique = mysql_query($query_gnewsid_unique);

$row_gnewsid_unique = mysql_fetch_array($result_gnewsid_unique);
$newsid_unique = $row_gnewsid_unique['newsid'];


// query to extract last title from tblnews 
$query_gtitle_unique = "SELECT title
FROM tblnews
WHERE newsid = $newsid_unique"; 
$result_gtitle_unique = mysql_query($query_gtitle_unique);

$row_gtitle_unique = mysql_fetch_array($result_gtitle_unique);
$title_unique = $row_gtitle_unique['title'];



if ($title == $title_unique) {  
$message_unique = "You have already entered this record.";  
$unique = TRUE;
}


Steve

-Original Message-
From: Burhan Khalid [mailto:[EMAIL PROTECTED] 
Sent: 17 December 2004 13:07
To: S.D.Price
Subject: Re: [PHP] Refreshing page after form submission


S.D.Price wrote:
> Hi, I have a form which when submitted adds a record to a DB. However 
> if the user clicks back it resubmits the same record.
> 
> I have tried using cache control to no avail :
> 
> header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
> header ("Last-Modified:" . gmdate("D, d M Y H:i:s"). " GMT"); header 
> ("Cache-control: no-store, no-cache, must revalidate");
> header("Cache-control: post-check=0, pre-check=0, false"); header 
> ("Pragma: no-cache"); session_cache_limiter("nocache");
> 
> I also tried testing for the presence of a submit button so if the 
> user enters data submits the form and clicks back the page will 
> refresh.
> 
>  
> if ($_POST['submit']) {
> echo "";
> } else { 
> } 
> ?>
> 
You can try and check if the user's information already exists in the 
database, then display an appropriate message.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php