Jump to content

Archived

This topic is now archived and is closed to further replies.

Ghostu

Stopping POSTDATA from being resent?

Recommended Posts

I made a comment script where users can type their comment into a form and then press submit to add it to my database. It works fine except for that if a user submits a comment, but then refreshes the page, the POSTDATA is resent and then the comment is posted again. So everytime the page is refreshed the same comment is added. What can I do about this?
Heres the script in action: [url=http://photoshopandyou.com/tutorials/view.php?action=view&id=7]http://photoshopandyou.com/tutorials/view.php?action=view&id=7[/url]
And the code:
[code]//Comments
//The date
$date = date('F jS, Y g:i a');
//Variables
if(isset ($_POST['submit'])) {
//Simplifying the variables.
$title = $_POST['title'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
//Checks for empty fields or invalid date.
if((empty($title)) OR (empty($name)) OR (empty($email)) OR (empty($message))) {
echo "<center><strong>Please fill in all fields!</strong></center>";
} else {
//The MySQL query which will insert content into the table.
mysql_query("INSERT INTO tutorial_comments (ID, tutorial_id, title, date, name, email, message) VALUES ('', '$id', '$title', '$date', '$name', '$email', '$message')") or die(mysql_error());
echo "<center><strong>Comment added!</strong></center>";
}
}[/code]
Thanks.

Share this post


Link to post
Share on other sites
Thanks alot, that works, but one last question how would I use that to direct them back to the page they left the comment on?
Thanks again!

Share this post


Link to post
Share on other sites
Thanks man it worked, the sites dynamic so had to use some extra code like this:
[code]$page = $_SERVER['REQUEST_URI'];
$host  = $_SERVER['HTTP_HOST'];
$extra = $page;
header("Location: http://$host/$extra");[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.