我有這樣的代碼:PHP IP記錄錯誤
<?php
echo $_POST['id-input'];
$time = time();
$ip=$_SERVER['REMOTE_ADDR'];
$userid_c = $_POST['id-input'];
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("kritya20_data", $con);
$sql = "SELECT * FROM users_online WHERE user_id='$userid_c'";
$query = mysql_query($sql);
$rows_only_c = mysql_num_rows($query);
if($rows_only_c == 0)
{
$sql1= "INSERT INTO users_online (user_id , online_since , lastup , lobbieid)
VALUES ('$userid_c' , '$time' , '$time' , '1')";
$query1 = mysql_query($sql1);
}
elseif($rows_only_c==1)
{
$sql2 = "UPDATE users_online
SET lastup='$time'
WHERE user_id='$userid_c' ";
$query2 = mysql_query($sql2);
}
$sql3 = "SELECT * FROM iptable WHERE user_id='$userid_c'";
$query3 = mysql_query($sql3);
$row_ip = mysql_num_rows($query3);
if($row_ip==0)
{
$sql4 = "INSERT INTO iptable (user_id , ip , added)
VALUES ('$userid_c' , '$ip' , '$time')";
$query4= mysql_query($sql4);
}
elseif($row_ip>0)
{
$mt=0;
$mf=0;
$sql4 = "SELECT * FROM iptable WHERE user_id='$userid_c'";
$query4 = mysql_query($sql4);
while($row=$query4)
{
if($ip==$row[2])
{
$mt++;
}
else
{
$mf++;
}
}
if($mf!=0)
{
$sql5 = "INSERT INTO iptable (user_id , ip , added)
VALUES ('$userid_c' , '$ip' , '$time')";
$query5= mysql_query($sql5);
}
}
?>
哪裏都被我的問題呢? :O ,因爲它只是第一次添加,然後每當ip改變它不會。
......哦哇。我沒有想到這= = – kritya 2011-06-05 08:48:15
我不認爲代碼是可怕的(雖然它有[SQL注入漏洞](http://php.net/manual/en/security.database.sql-injection.php)需要修復),但是您確實需要先進行一些調試,嘗試找出問題所在,並添加更詳細的信息。我們無法爲您執行這些步驟 – 2011-06-05 09:25:31
'canuwritetehcodezplz' – Petah 2011-06-05 09:43:26