该代码用于更新用户登录的IP地址。当我打印$sql字符串时,似乎是正确的,IP地址是1886883852,但更新到mysql后,值为2149463110。我尝试设置mysql中的数据类型为INT(11) bigint(12),都一样。如果我尝试将字符串写为
UPDATE ddns SET LastIP=1886883852, LastUpdate=now() WHERE ID=1
直接,不使用任何变量,它可以正常工作。
实在看不懂。有人可以帮忙吗?
//get dns
function getIP(){
//check the current ip address registered
//Test if it is a shared client
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
$ipaddr=$_SERVER['HTTP_CLIENT_IP'];
//Is it a proxy address
}elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ipaddr=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ipaddr=$_SERVER['REMOTE_ADDR'];
}
$ipaddr = ip2long($ipaddr);
return $ipaddr;
}
$ipaddr = getIP();
$sql = "UPDATE ddns SET LastIP=$ipaddr, LastUpdate=now() WHERE ID=1";
echo $sql; **//here UPDATE ddns SET LastIP=1886883852, LastUpdate=now() WHERE ID=1**
$result = mysqli_query($dbh,$sql) or die("Query failed:");
**//Here after updated, the value of ipaddr in database is 2149463110**
if ($result)
echo "Update ddns successfully";
else
echo "faild to update ddns";