输出:
警告:mysql_query():6不是C语言中有效的MySQL-Link资源:第94行的... \ mysql_helper.php
$con = mysql_connect($GLOBALS['mysql_host'], $GLOBALS['mysql_username'], $GLOBALS['mysql_password']) or die(mysql_error());
$db = mysql_select_db($GLOBALS['mysql_database']) or die(mysql_error($con));
$username=sanitize_mysql($username);
$password=sanitize_mysql($password);
$email=sanitize_mysql($email);
if(check_exists("users", "username", $username) == FALSE){
$query = "INSERT INTO users VALUES('".$username."','".$password."','".$email."','".$status."','".$reg_date."','".$own_ref_id."','')";
$result = mysql_query($query,$con) or die(mysql_error($con));
return TRUE;
} else {
return FALSE;
}
mysql_close($con);
适用于此类构建的所有其他功能(复制/粘贴)
这是check_exists
function check_exists($table,$specifier,$value)
{
$con = mysql_connect($GLOBALS['mysql_host'], $GLOBALS['mysql_username'], $GLOBALS['mysql_password']) or die(mysql_error());
$db = mysql_select_db($GLOBALS['mysql_database']) or die(mysql_error($con));
$query = "SELECT * FROM ".$table." WHERE ".$specifier." = '".$value."'";
$erg = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($erg)) {
mysql_close($con);
return TRUE;
}
mysql_close($con);
return FALSE;
}
答案 0 :(得分:4)
$con
中的check_exists()
似乎与$con
的范围相同,因此check_exists()
首先覆盖(并丢失)原始连接,然后在调用mysql_close($con)
时关闭自己的连接。
最好保持一个单独的连接,以便使用所有这些功能。