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
https://forums.phpfreaks.com/topic/21085-stopping-postdata-from-being-resent/
Share on other sites

Archived

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

×
×
  • 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.