广告广告
  加入我的最爱 设为首页 风格修改
首页 首尾
 手机版   订阅   地图  繁体 
您是第 37492 个阅读者
 
发表文章 发表投票 回覆文章
  可列印版   加为IE收藏   收藏主题   上一主题 | 下一主题   
lkk47
个人文章 个人相簿 个人日记 个人地图
小人物
级别: 小人物 该用户目前不上站
推文 x16 鲜花 x10
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片
推文 x0
[求助] php网站计数器问题 高手帮看程式码
【类型】其他
【版本】其他

我照书上做网站人数计数器  但是我测试时计数器都是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);
?>



献花 x0 回到顶端 [楼 主] From:台湾凯擘 | Posted:2010-01-27 11:41 |
johnroyer 手机
个人头像
个人文章 个人相簿 个人日记 个人地图
特殊贡献奖
小有名气
级别: 小有名气 该用户目前不上站
推文 x8 鲜花 x505
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

SQL 语法有错误

你可以先把程式产生的 SQL 语法 echo 出来
贴到 phpMyAdmin 上面跑跑看


My Blog : Zeroplex
Plurk : Zeroplex
献花 x0 回到顶端 [1 楼] From:台湾中华电信 | Posted:2010-01-30 20:27 |

首页  发表文章 发表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.114320 second(s),query:16 Gzip disabled
本站由 瀛睿律师事务所 担任常年法律顾问 | 免责声明 | 本网站已依台湾网站内容分级规定处理 | 连络我们 | 访客留言