【类型】其他
【版本】其他
我照书上做网站人数计数器 但是我测试时计数器都是0 高手帮我看一下 我是新手还在努力学习中
如果复杂 可以帮我看看红色区域有没有问题 蓝色区域我放一个%的画 策是网页会显示
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' at line 1
各位高手帮帮忙 这问题卡一段时间 我要想办法解决 谢谢高手
<?php require_once('Connections/conncoumter.php'); ?>
<?php
$nowtime=date("Y-m-d H:i:s"); //设定代表目前时间的变数
session_start(); //启动Session的使用
if(!isset($_SESSION['counter'])){ //检查Session值是否存在
mysql_select_db($database_conncoumter, $conncoumter); //连结资料库
$userIP=$_SERVER['REMOTE_ADDR']; //收集浏览者的IP
$insertCommand="INSERT INTO webcount (count_id, count_ip,count_time)
VALUES (NULL, '$userIP', '$nowtime')"; //新增资料的SQL字串
mysql_query($insertcommand,$conncoumter); //执行webcount资料库的新增
$_SESSION['counter'] = 1; //设定Session值
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$comparetoday_today = date("Y-m-d");
mysql_select_db($database_conncoumter, $conncoumter);
$query_today = sprintf("SELECT * FROM webcount WHERE count_time LIKE CONCAT(%s, '%%')", GetSQLValueString($comparetoday_today, "text"));
$today = mysql_query($query_today, $conncoumter) or die(mysql_error());
$row_today = mysql_fetch_assoc($today);
$totalRows_today = mysql_num_rows($today);$comparethismonth_thismonth = date("Y-m");
mysql_select_db($database_conncoumter, $conncoumter);
$query_thismonth = sprintf("SELECT * FROM webcount WHERE count_time LIKE CONCAT(%s, '%%')", GetSQLValueString($comparethismonth_thismonth, "text"));
$thismonth = mysql_query($query_thismonth, $conncoumter) or die(mysql_error());
$row_thismonth = mysql_fetch_assoc($thismonth);
$totalRows_thismonth = mysql_num_rows($thismonth);$comparethisyear_thisyear = date("Y");
mysql_select_db($database_conncoumter, $conncoumter);
$query_thisyear = sprintf("SELECT * FROM webcount WHERE count_time LIKE CONCAT(%s, '%%')", GetSQLValueString($comparethisyear_thisyear, "text"));
$thisyear = mysql_query($query_thisyear, $conncoumter) or die(mysql_error());
$row_thisyear = mysql_fetch_assoc($thisyear);$totalRows_thisyear = mysql_num_rows($thisyear);mysql_select_db($database_conncoumter, $conncoumter);
$query_total = "SELECT * FROM webcount";
$total = mysql_query($query_total, $conncoumter) or die(mysql_error());
$row_total = mysql_fetch_assoc($total);
$totalRows_total = mysql_num_rows($total);$timesec=gettimeofday();
$tmp=file("time.txt");
if ($tmp[0]==""){
$fopen0=fopen("time.txt","w+");
fputs($fopen0,$timesec["sec"]);
fclose($fopen0);
$fopen1=fopen("ip.txt","w+");
fputs($fopen1,"");
fclose($fopen1);
}
$tmp1=file("time.txt");
$equal=($timesec["sec"]-$tmp1[0]);
if ($equal>60){
$fopen0=fopen("time.txt","w+");
fputs($fopen0,"");
fclose($fopen0);
}
$fopen=fopen("ip.txt","a+");
$ip=$HTTP_SERVER_VARS['REMOTE_ADDR'];;
$flag=1;
$tmp2=file("ip.txt");
$con=count($tmp2);
for ($i=0;$i<$con;$i++){
if ($ip."\n"==$tmp2[$i]){
$flag=0;
break;
}
}
if ($flag==1){
$ipstring=$ip."\n";
fputs($fopen,$ipstring);
}
fclose($fopen);
$tmp3=file("ip.txt");
$onlineusr=count($tmp3);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DT...sitional.dtd">
<html xmlns="
http://www.w3.or.../xhtml">
<head>
<?php echo "<meta http-equiv=\"Refresh\" content=\"30\" />";?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文件</title>
<style type="text/css">
<!--
.style1 {color: #0000FF}
.style2 {color: #0033CC}
.style3 {color: #003399}
-->
</style>
<script type="text/JavaScript">
<!--
function centerWindow(theURL,winName,width,height,features) {
var window_width = width;
var window_height = height;
var edfeatures= features;
var window_top = (screen.height-window_height)/2;
var window_left = (screen.width-window_width)/2;
newWindow=window.open(''+ theURL + '',''+ winName + '','width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + ',features=' + edfeatures + '');
newWindow.focus();
}
//-->
</script>
</head>
<body>
<div align="center">浏览人次:今年<span class="style1"></span><?php echo $totalRows_thisyear ?> 人,
本月<span class="style2"></span> <?php echo $totalRows_thismonth ?> 人,今天<span class="style3"></span> <?php echo $totalRows_today ?> 人 ,总人次<span class="style2"></span> <?php echo $totalRows_total ?> 人,目前线上人数为<?php echo $onlineusr;?>。 <<a href="javascript:;" onclick="centerWindow('showVisit.php','showVisit','800','800','')">最新浏览者资料</a>> </div>
</body>
</html>
<?php
mysql_free_result($today);
mysql_free_result($thismonth);
mysql_free_result($thisyear);
mysql_free_result($total);
?>