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错误-注意:未定义变量:第135行D:\iac\htdocs\datas\scripts\iAccount\u core.inc.php中的iAccount\u db_Php_Variables_Undefined - Fatal编程技术网

php错误-注意:未定义变量:第135行D:\iac\htdocs\datas\scripts\iAccount\u core.inc.php中的iAccount\u db

php错误-注意:未定义变量:第135行D:\iac\htdocs\datas\scripts\iAccount\u core.inc.php中的iAccount\u db,php,variables,undefined,Php,Variables,Undefined,我正在运行一个PHP脚本,不断出现如下错误: 注意:未定义的变量:第135行D:\iac\htdocs\datas\scripts\iAccount\u core.inc.php中的iAccount\u db 但是我已经定义了变量 代码: iAccount_core.inc.php ... require_once("iAccount_config.inc.php"); ... function iAccount_level_update($user){ $result = mysql_quer

我正在运行一个PHP脚本,不断出现如下错误: 注意:未定义的变量:第135行D:\iac\htdocs\datas\scripts\iAccount\u core.inc.php中的iAccount\u db

但是我已经定义了变量

代码:

iAccount_core.inc.php

...
require_once("iAccount_config.inc.php");
...
function iAccount_level_update($user){
$result = mysql_query ("SELECT exp FROM $iAccount_table WHERE username='$user'");
    $exp = @mysql_result($result, "exp");
if ($exp > -1 and $exp < 61){$update_lev = 1;}
if ($exp > 60 and $exp < 101){$update_lev = 2;}
if ($exp > 100 and $exp < 6001){$update_lev = 3;}
if ($exp > 600 and $exp < 1001){$update_lev = 4;}
if ($exp > 1000 and $exp < 6001){$update_lev = 5;}
if ($exp > 5999){$update_lev = 6;}
mysql_query("UPDATE $iAccount_table SET level='$update_lev' WHERE username='$user'", $iAccount_db);
}
function iAccount_level_size($user){
$result = mysql_query ("SELECT level FROM $iAccount_table WHERE username='$user'");
    $level = @mysql_result($result, "level");
if ($level = 0 or $level = ""){iAccount_level_update($user);}
if ($level = 1){$size = $iAccount_level_maxsize[1];}
if ($level = 2){$size = $iAccount_level_maxsize[2];}
if ($level = 3){$size = $iAccount_level_maxsize[3];}
if ($level = 4){$size = $iAccount_level_maxsize[4];}
    if ($level = 5){$size = $iAccount_level_maxsize[5];}
    if ($level = 6){$size = $iAccount_level_maxsize[6];}
    $size = $size*1024; // return KB
    return($size);
}
function iAccount_level_addexp($exp, $user){
    $result = mysql_query ("SELECT exp FROM $iAccount_table WHERE username='$user'");
    $expp = @mysql_result($result, "exp");
    $update_exp = $expp+$exp;
    mysql_query("UPDATE $iAccount_table SET exp='$update_exp' WHERE username='$user'", $iAccount_db);
}
function iAccount_dirsize($dirName = '.') {
$dir = dir($dirName);
$size = 0;

while($file = $dir->read()) {
echo "$dirName/$file"." -> ".filesize("$dirName/$file")."n";
if ($file != '.' && $file != '..') {
if (is_dir("$dirName/$file")) {
$size += dirsize($dirName . '/' . $file);
} else {
$size += filesize($dirName . '/' . $file);
}
}
}
$dir->close();
return $size;
}
...
$iAccount_db = mysql_connect($iAccount_sql_server, $iAccount_sql_username, $iAccount_sql_password) or iAccount_die('Unable to connect to database. Please check your iAccount MySQL server, username and password configuration options.');
mysql_select_db($iAccount_sql_database, $iAccount_db) or iAccount_die('Unable to select the database. Please check your iAccount MySQL database configuration option.');

好的,现在您发布了一些代码,您在正确的位置定义了
$iAccount\u db
,但是您试图在内部访问它,而变量是在外部定义的

错误的解决方案:将
$iAccount\u db
设为全局(不推荐)

一种变体是使这些变量成为常量,因为实际上它们就是常量

更好的解决方案:将变量作为参数传递给函数:

function iAccount_level_update($user, $iAccount_db){ }

此外,您的查询很容易受到SQL注入的影响(在需要时,至少使用mysql\u real\u escape\u string),我建议切换到mysqli或更好的PDO,并使用查询参数化。

您可以向我们展示代码吗?您是否希望人们从未知源下载未知存档,浏览您的“这么长”代码(如果这是实际内容)并为您找出错误?为什么不在这里发布相关内容?谢谢。问题已经解决了resolved@Birkhoff,这可能是由于php.ini中的更改。以前,php没有显示警告(但错误就在那里),现在显示了。
function iAccount_level_update($user, $iAccount_db){ }