php错误 - 注意:未定义的变量:第135行的D:\ iac \ htdocs \ datas \ scripts \ iAccount_core.inc.php中的iAccount_db [关闭]

I am running a PHP script, and keep getting errors like: Notice: Undefined variable: iAccount_db in D:\iac\htdocs\datas\scripts\iAccount_core.inc.php on line 135

But I have already defined the variable!

code:

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_config.inc.php

...
$iAccount_sql_server = "localhost";
$iAccount_sql_username = "root";
$iAccount_sql_password = "test";
$iAccount_sql_database = "test";
$iAccount_table = "iAccount";
...

Ok, now that you posted some code, you're defining $iAccount_db in the correct place, but you're trying to access it when inside the scope of a funcion , while the variable is defined outside of it.

Bad solution: make $iAccount_db global (not recommended)

A variant to this would be to make those variable CONSTANTS, since actually that's what they are.

Better solution: pass the variable as an argument to your function:

function iAccount_level_update($user, $iAccount_db){ }

Also, your queries are vulnerable to SQL injection (use mysql_real_escape_string at the very least, when required), I suggest switching to mysqli or even better PDO and use query parametrization.