检查WHERE user = $ name行中的特定整数 [英] Check for specific integer in a row WHERE user = $name

查看:112
本文介绍了检查WHERE user = $ name行中的特定整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我想做的:用户可以注释一次最多五次(在代码中我使用60秒查看结果更快)。
但是我似乎做了一个错误的比较,因为现在它总是给我回来了。因此,即使计数器在5以上,它仍然计数,而不是停在那里(60秒)。
任何输入是赞赏。下面是我使用的代码。

Here is what I wanna do: User can comment up to five times a day (in code I use 60 seconds to see the result quicker). However I seem to make a wrong comparison, because right now it always gives me back true. So even if the counter is above 5, it still counts up instead of stopping there (for 60 seconds). Any input is appreciated. Down below is the code I use.

<?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
?>


推荐答案

p>看起来您尝试在等待时间后使用此命令运行查询:

It looks like you are trying to run the query after a wait time with this command:

 set_time_limit(60);  

这使脚本的最大运行时间为60秒,但实际上并不执行任何操作。更改设置,使您的脚本 最多可运行1分钟,但实际上不会运行。

This makes the maximum run time of your script 60 seconds, but doesn't actually do anything more. It changes a setting so your script could run a maximum of 1 minute, but doesn't actually make it run.

sleep 但你不应该如果你想做一天,这意味着你的脚本会运行一天(它可以,睡眠不计数它是一个系统调用)。

You could do it with sleep but you shouldn't If you want to do it for a day, that means your script would run for a day (it can, sleep doesn't "count" as it is a system call).

更好地写一定的时间到你的数据库,并检查。如果用户要对您发表评论,请检查

Better write a certain time to your database and check against that. If the user wants to comment you check

检查用户是否有5条评论。

Check if the user has 5 comments.


  1. 是吗?检查时间

    1.如果它在过去,发布评论并重置计数器。

  1. Yes? check the time
    1.if it is in the past, post the comment and reset the counter.

  1. 如果将来,不要发布评论。


  • 不是?增加计数器并发布评论

  • No? increase the counter and post the comment


    1. 是否将其增加到5?然后将日期设置为+60秒(或+1天)。


  • 这篇关于检查WHERE user = $ name行中的特定整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆