2011-01-06 7 views
0

私のPHPクエリでエラーメッセージが表示されます。私のPHPクエリでエラーが発生する

エラーが表示されます: SQL構文にエラーがあります。ラインに近い「1294251744」、「127.0.0.1」、「)「/登録」を使用する権利構文についてはMySQLサーバのバージョンに対応するマニュアルを確認してください2

私のコード:

<?php 
require_once("includes/database.php"); 

//Set timeout to 5 minutes 
$timeoutseconds = 300 ; 

//get the time 
$timestamp = time(); 
//Delete all users that are no online after the time out allowed 
$timeout = $timestamp - $timeoutseconds ; 

// stores users IP addresss 
$user_ip = $_SERVER['REMOTE_ADDR']; 
// Automatically collects the hostname or domain like example.com) 
$host = $_SERVER['HTTP_HOST']; 
$host_upper = strtoupper($host); 
$path = rtrim(dirname($_SERVER['PHP_SELF']), '/'); 

//insert the values 
$sql = "INSERT INTO totalonline(timestamp, ip, file) 
      VALUES (''$timestamp','$user_ip','$path')"; 

    $result = mysql_query($sql, $conndb) or die(mysql_error()); 


//delete values when they leave 
mysql_query("DELETE FROM totalonline WHERE timestamp < $timeout"); 

//grab the results 
$sql = "SELECT DISTINCT ip FROM totalonline WHERE file='$path' "; 

    $result = mysql_query($sql, $conndb) or die(mysql_error()); 

//number of rows = the number of people online 
    $user = mysql_num_rows($result); 


//spit out the results 

if($user == 1) { 
echo "$user User online"; 
} else { 
echo "$user User online"; 
} 

?> 
+0

//値を挿入してください $ sql = "INSERT INTO totalonline(タイムスタンプ、IP、ファイル) VALUES( '' $ timestamp '、' $ user_ip '、' $ path ')"; タイムスタンプの前に余分な引用符があります。 – fiunchinho

+0

"私のPHPクエリでエラーメッセージが表示されています。"、ok。それについてもっと情報を共有したいのですか、それとも泣かなければなりませんか?私は彼の背景、答え、質問を検索し、人々が彼をどれほど憎んでいるのかは驚くほどです。3,2,2,3でフラグを付ける。 – Shoe

+0

だから私はこの質問にフラグを立てた。 – Shoe

答えて

3

これに

//insert the values 
$sql = "INSERT INTO totalonline(timestamp, ip, file) 
      VALUES (''$timestamp','$user_ip','$path')"; 

:これを変更

//insert the values 
$sql = "INSERT INTO totalonline(timestamp, ip, file) 
      VALUES ('$timestamp','$user_ip','$path')"; 

次の2つの単一引用符の代わりのものを持っていました。


また、終わり近くに、あなたはおそらくこれを変更したい:

if($user == 1) { 
echo "$user User online"; 
} else { 
echo "$user User online"; 
} 

これに:あなたは値フィールドに「ダブル持っ

if($user == 1) { 
echo "$user User online"; 
} else { 
echo "$user User offline"; 
} 
1

;)

//insert the values 
$sql = "INSERT INTO totalonline(timestamp, ip, file) 
      VALUES (''$timestamp','$user_ip','$path')"; 

$タイムスタンプの直前。

そのようにあなたがDBはIPとパスが文字列であることを確認し理解しているのでそれは

//insert the values 
$sql = 'INSERT INTO totalonline(timestamp, ip, file) 
      VALUES ('.$timestamp.',"'.$user_ip."',"'.$path.'")'; 

を行う方が良いでしょう。

関連する問題