Jump to content

Stopping POSTDATA from being resent?


Ghostu

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.