Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php中奇怪的变量行为,尽管数据在变量中可用_Php_Variables - Fatal编程技术网

php中奇怪的变量行为,尽管数据在变量中可用

php中奇怪的变量行为,尽管数据在变量中可用,php,variables,Php,Variables,我正在通过一个小php脚本使用第三方免费服务更新数据库中的IP位置。它工作正常,但突然停止工作。我试图弄清楚发生了什么事,但弄不清楚。这是我的剧本 <? $sno = 0; $query = "SELECT date,ac_no,ip,country FROM visitors where $mainfilter order by ac_no,date desc limit 0,$maximumips;"; $result = db_query($query,"&nbsp;");

我正在通过一个小php脚本使用第三方免费服务更新数据库中的IP位置。它工作正常,但突然停止工作。我试图弄清楚发生了什么事,但弄不清楚。这是我的剧本

<?
$sno = 0;
$query = "SELECT date,ac_no,ip,country FROM visitors where $mainfilter order by ac_no,date desc limit 0,$maximumips;";

$result = db_query($query,"&nbsp;");
while($line=db_fetch_array($result))
{

$country = "";
$updatestatus = "";
$ip = $line[ip];
$sno = $sno + 1;

if($updateip=="Yes")
{
    $ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip));
    if($ip_data && $ip_data->geoplugin_countryName != null)
    {
        $country = $ip_data->geoplugin_countryName;
    }

    if($country!="")
    {
        $q_det = "update visitors set country='$country' where ip='$line[ip]'";
        db_exec($q_det);

        $q_det = "update ips set country='$country' where ip='$line[ip]'";
        db_exec($q_det);
        $updatestatus = "Yes - External";
    } else {
        $updatestatus = "No Trace";
    }
    sleep($waitseconds);        
}

echo "$sno | $line[date] | $line[ac_no] | $ip | $country | $updatestatus";?><br><?
}
?>
然后我想将IP存储在$IP变量中,然后在那里使用,但仍然不起作用

请帮助我了解为什么cpanel-givers出现错误,脚本停止,尽管它工作正常,并且数据存储在$ip变量中,该变量显示何时使用“echo$ip”


感谢您的帮助

将数组键括在引号中”将修复它。如果没有引号,PHP假定它是一个
常量,因此抛出一个错误

$ip = $line['ip'];
还可以在
更新
查询中更改变量名称

$q_det = "update visitors set country='$country' where ip='$ip'";
$q_det = "update ips set country='$country' where ip='$ip'";

将数组键括在引号中将修复它。如果没有引号,PHP假定它是一个
常量,因此抛出一个错误

$ip = $line['ip'];
还可以在
更新
查询中更改变量名称

$q_det = "update visitors set country='$country' where ip='$ip'";
$q_det = "update ips set country='$country' where ip='$ip'";

尝试使用不带引号的
ip
$ip=$line[ip]
更改为
$ip=$line['ip']
,php将其视为

并修复您的查询

$q_det = "update visitors set country='$country' where ip=$ip";
db_exec($q_det);

$q_det = "update ips set country='$country' where ip=$ip";
db_exec($q_det);

尝试使用不带引号的
ip
$ip=$line[ip]
更改为
$ip=$line['ip']
,php将其视为

并修复您的查询

$q_det = "update visitors set country='$country' where ip=$ip";
db_exec($q_det);

$q_det = "update ips set country='$country' where ip=$ip";
db_exec($q_det);

他的查询部分仍然是错误的,他不能只在ip上添加一个qoute,也请更正查询部分仍然是错误的,他不能只在ip上添加一个qoute,也请更正查询部分仍然是错误的,他不能只在ip上添加一个qoute,也请更正查询。我想我和Samir都认为他使用的是变量,而不是
$line[ip]
,因为他说“然后我想把ip存储在$ip变量中,然后在那里使用,但仍然不起作用。”他的查询部分仍然是错的,他不能只在ip周围添加一个qoute,也请更正查询。我想我和Samir都认为他使用的是变量而不是
$line[ip]
,因为他说“然后我想把ip存储在$ip变量中,然后在那里使用,但仍然不起作用。”