这是我想做的:用户一天最多可以评论五次(在代码中我使用 60 秒来更快地查看结果)。但是我似乎做了一个错误的比较,因为现在它总是让我回到真实的状态。因此,即使计数器高于 5,它仍然会计数而不是停在那里(60 秒)。任何输入表示赞赏。下面是我使用的代码。
<?php
$DB_HostName = "";
$DB_Name = "";
$DB_User = "";
$DB_Pass = "";
$DB_Table = "";
$name = mysql_escape_string($_GET['name']);
set_time_limit(0);
$con = mysql_connect($DB_HostName,$DB_User,$DB_Pass) or die (mysql_error());
mysql_select_db($DB_Name,$con) or die(mysql_error());
if ($name[CommentCounterReset] === 5) //or if ("CommentCounterReset === 5 WHERE Name = $name)? {
echo "You already wrote five comments.";
set_time_limit(60);
$sql = "UPDATE table SET CommentCounterReset = CommentCounterReset-5 WHERE Name = '$name'";
} else {
$sql = "UPDATE table SET CommentCounterReset = CommentCounterReset+1 WHERE Name = '$name'";
echo "Comment accepted.";
}
$res = mysql_query($sql,$con) or die(mysql_error());
mysql_close($con);
if ($res) {
}else{
}// end else
?>