[英]Comment the same again and again
I am trying to make a comments section, where people can comment stuff on my webpage. 我正在尝试创建评论部分,以便人们可以在我的网页上发表评论。 All the comments get to a database.
所有的评论都进入数据库。 Alle that works fine.
一切正常。 The only problem I have is, when i have commented some stuff and reload the webpage it comment the same thing again.
我唯一的问题是,当我评论了一些内容并重新加载网页后,它再次评论了同一件事。
Is there a if statement or something to prevent this? 是否有if语句或其他方法可以防止这种情况?
while ($info = mysql_fetch_array($result)){
echo '<div style="border-style: solid; border-color: #808080; border-width: thin">
<div style="width: 1%"><p style="font-size: 10px; margin: 0px">'.$info['Navn'].'</p></div>
<p>'.$info['Besked'].'</p>
</div>';
}
if (isset($_POST['navn']) && isset($_POST['besked']) && isset($_POST['submit'])) {
$navn2 = $_POST['navn'];
$besked2 = $_POST['besked'];
$data = "INSERT INTO `tester`.`davs` (`Navn`, `Besked`) VALUES ('$navn2', '$besked2');";
$resultalt = mysql_query($data);
if ($resultalt) {
echo "$resultat";
}else{
echo "$resultat";
}
mysql_close();
}
?>
<form action="database.php" method="post" id="commentform">
<label for="comment_author" class="required">Your name</label>
<input type="text" name="navn" id="comment_author" value="" tabindex="1" required="required">
<label for="comment" class="required">Your message</label>
<textarea name="besked" id="comment" rows="10" tabindex="4" required="required"></textarea>
<input type="hidden" name="comment_post_ID" value="1" id="comment_post_ID" />
<input name="submit" type="submit" value="Submit comment" />
</form>
my php code: http://pastebin.com/bQ7c1MPD my inputs: http://pastebin.com/P9uc6Hhz 我的php代码: http : //pastebin.com/bQ7c1MPD我的输入: http : //pastebin.com/P9uc6Hhz
Use tokens in your HTML form: 在您的HTML表单中使用令牌:
<input type="hidden" name="token" value="<?=$_SESSION['token'] = uniqid(); ?>" />
This require this at the top of the PHP script (before any output): 这要求在PHP脚本的顶部(在任何输出之前):
session_start();
For validation: 进行验证:
if(isset($_POST['submit']) && $_POST['token'] == $_SESSION['token']))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.