开发者

Submit comment or suggestions or feedback

Hi I want to inplement a comment system but the problem is that , if user refresh the page then it gets saved to database again. I have done same thing on my other website but there it is for single page so I have used header(location: index.php ) there so that refresh does not work , but here I am using a template.php file which is being used in 200 pages , so I have put the comment form in template.php (which is included in all pages). Please help me with this.I just want comment not be saved agaun and again if user refreshes the page. Thanks.

After reading a lot this is the code I am using my form action="addcomment.php" and addcomment.php has following code

<?php
require_once("appvars.php");
require_once("connectvars.php");
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === 1){
  $_POST = array_map( 'stripslashes', $_POST );
  $_GET = array_map( 'stripslashes', $_GET );
  $_COOKIE = array_map( 'stripslashes', $_COOKIE );
}
if (isset($_POST['commentsubmit']))
{
$type=mysqli_real_escape_string($dbc,trim($_POST['type']));
$name=mysqli_real_escape_string($dbc,trim($_POST['username']));
$email=mysqli_real_escape_string($dbc,trim($_POST['useremail'];))
$subject=mysqli_real_escape_string($dbc,trim($_POST['subject']));
$comment=mysqli_real_escape_string($dbc,trim($_POST['usercomment']));
$link=mysqli_real_escape_string($dbc,trim($_POST['link']));
$query = "INSERT INTO comments (`t开发者_如何学Goype`,`name`,`email`,`subject`,`comment`,`date`,`link`) VALUES         ('$type','$name','$email','$subject','$comment',NOW(),'$link')";
$result=mysqli_query($dbc, $query) or die('error query'); 
?>

Please let me know how to redirect to the link stored in variable $link and send Thanks if query executed sucessfully


Common practice is to post the form to ie. submit.php, which will save the comment and passes back (redirects) the user back to the page where the comment was placed. A refresh will just refresh the page and not reload. Other solutions are using an ajax form or pass an unique identifier with the form so it can not be posted twice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜