Ghostu Posted September 17, 2006 Share Posted September 17, 2006 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');//Variablesif(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. Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 17, 2006 Share Posted September 17, 2006 Instead of your 'Comment added!' line, doheader('location:wherever.php');That should fix it Quote Link to comment Share on other sites More sharing options...
Ghostu Posted September 17, 2006 Author Share Posted September 17, 2006 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! Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 17, 2006 Share Posted September 17, 2006 Just change the wherever.php to the name of the page you want them to go to and that should work Quote Link to comment Share on other sites More sharing options...
Ghostu Posted September 17, 2006 Author Share Posted September 17, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.