php網站計數器問題 高手幫看程式碼

Home Home
引用 | 編輯 lkk47
2010-01-27 11:41
樓主
推文 x0
【類型】其他
【版本】其他

我照書上做網站人數計數器  但是我測試時計數器都是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/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/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
引用 | 編輯 johnroyer
2010-01-30 20:27
1樓
  
SQL 語法有錯誤

你可以先把程式產生的 SQL 語法 echo 出來
貼到 phpMyAdmin 上面跑跑看

獻花 x0