一个php查询mysql数据库的问题!急!在线等! php mysqlmysql查询 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select count(*) from ` #@__sh` where ip='$ip' and to_days(time)=to_days(now()) $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{ ........继续发布................} $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条信息了,但是还是发布出去了,貌似跳过了那个判断咋回事? print_r($row); 打印出来啥都没有,为空!!! 没有错误信息么? echo mysql_error(); 看看。 Access denied for user 'ODBC'@'localhost' (using password: NO) 你的 ODBC 用户没有密码吗?连接数据库的代码贴出来看看。 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没有值??? $num=count($result); 这句删掉,我上面已经给出示例了啊。if($num['total'] > 10){ 这句也有问题,当已经有10条时还能发布。 本帖最后由 xuzuning 于 2014-03-30 22:14:54 编辑 php中,显示时如何将同一个人同一天的两条记录合为一条,将签退时间和签到时间显示在同一行? str_replace函数中的参数问题 PHP 怎么做如何定时发送邮件 unlink的问题 菜鸟问题=>字符的用法 liunx ssh下网站转向问题 求mysqli取得结果中指定字段的字段名 中间件是什么东东? 谁有操作mysql数据库的类,高分相送! PHP 删除文件 ob_start ob_end_clean()、ob_get_contents()是线程安全的吗 爬新浪网好友遇到的模拟登陆问题
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
if($row[0] == 10){
eco '不能再发布了';
exit(); //如果想退出程序,则可以加这行。
}else{
........继续发布................
}
$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条信息了,但是还是发布出去了,貌似跳过了那个判断咋回事?
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没有值???