解决方案 »

  1.   

    select count(*) from ` #@__sh` where ip='$ip' and to_days(time)=to_days(now())
      

  2.   

    $sql = "select count(*) from ` #@__sh` where ip='$ip' and FROM_UNIXTIME(time,'%Y-%m-%d')=curdate()";
    $result = mysql_query($sql);
    $row = mysql_fetch_row($result);
    if($row[0] == 10){
         eco '不能再发布了';
          exit();   //如果想退出程序,则可以加这行。
    }else{
       ........继续发布................
    }
      

  3.   


    $time = time(); //时间
    $ip = GetIP();$sql = "select count(*) from ` #@__sh` where ip='$ip' and FROM_UNIXTIME(time,'%Y-%m-%d')=curdate()";
    $result = mysql_query($sql);
    $row = mysql_fetch_row($result);
    if($row[0] >= 10){
    echo "<Script language='JavaScript'> alert('不能发布了');</Script>";
    echo "<meta http-equiv=refresh content=0;URL='javascript:window.history.back(1);'>";
    }
    else{
    $inQuery = "INSERT INTO `#@__sh` (`bzh`,`ws`, `wp`, `qq`, `sj`, `mm`, `time`,`ip`) 
    VALUES ('$bzh','$ws', '$wp', '$qq', '$sj', '$mm', '$time', '$ip');
    ;";
    if(!$dsql->ExecuteNoneQuery($inQuery)){
    $gerr = $dsql->GetError();
    $dsql->Close();
    ShowMsg("把数据保存到数据库 `$maintable` 时出错,请联系管理员!".$gerr,"-1");
    exit();
    }
    echo '<script language="JavaScript">window.alert("拾获登记提交成功,点击确定回网站首页");location.href="index.php"</script>';
    }
    我的代码按照您的这么写,还是不行,获取到的当前ip今天已经发布超过10条信息了,但是还是发布出去了,貌似跳过了那个判断咋回事?
      

  4.   

    print_r($row); 打印出来啥都没有,为空!!!
      

  5.   

    没有错误信息么? echo mysql_error(); 看看。
      

  6.   

    Access denied for user 'ODBC'@'localhost' (using password: NO)
      

  7.   

    你的 ODBC 用户没有密码吗?连接数据库的代码贴出来看看。
      

  8.   


    require_once("include/common.inc.php");$time = time(); //时间
    $ip = GetIP();$sql="SELECT count(*) as total from `dede_sh` where ip='$ip' and to_days(time)=to_days(now())"; 
    $result=mysql_fetch_array(mysql_query($sql)); 
    $num=count($result);if($num['total'] > 10){
    echo "<Script language='JavaScript'> alert('每天只能发布10条信息,不能再发布了');</Script>";
    echo "<meta http-equiv=refresh content=0;URL='javascript:window.history.back(1);'>";

    else{
    $inQuery = "INSERT INTO `#@__sh` (`bzh`,`ws`, `wp`, `qq`, `sj`, `mm`, `time`,`ip`) 
    VALUES ('$bzh','$ws', '$wp', '$qq', '$sj', '$mm', '$time', '$ip');
    ;";
    if(!$dsql->ExecuteNoneQuery($inQuery)){
    $gerr = $dsql->GetError();
    $dsql->Close();
    ShowMsg("把数据保存到数据库 `$maintable` 时出错,请联系管理员!".$gerr,"-1");
    exit();
    }
    echo '<script language="JavaScript">window.alert("拾获登记提交成功,点击确定回网站首页");location.href="index.php"</script>';

    这是我所有的代码,数据库连接没有任何问题,我测试的时候,我的ip今天已经发布超过10条信息,但是还能继续正常发布信息,表单信息正常插入到数据库表,这说明我的数据库连接没有问题。不知道怎么回事就是获取的$num没有值???
      

  9.   

    $num=count($result);  这句删掉,我上面已经给出示例了啊。if($num['total'] > 10){  这句也有问题,当已经有10条时还能发布。
      

  10.   

    本帖最后由 xuzuning 于 2014-03-30 22:14:54 编辑