我在堆栈上搜索有关此问题的信息,但一无所获。这可能是一个语法问题,但我不明白。
//Include necessary files
include_once("inc/mysql.inc.php");
include_once("inc/security.inc.php");
//SECURITY: Check input before adding them into the table.
$u = security_checkinput($u);
//Connect to the MySQL database.
mysql_dbconnection();
//Go get users id corresponding to the search
$u = mysql_query("SELECT id FROM users
WHERE name LIKE \"%$u%\" OR active LIKE \"%$u%\"
ORDER BY name ASC") or die("There is a server error : " . mysql_error());
$u = mysql_fetch_row($u);
//Close database connection
mysql_dbclose();
//Return the array.
return $u;
查询后我在 $u 上尝试了 mysql_num_rows,它返回 0。不幸的是,用户表和名称列中有一些东西。
有什么帮助吗?非常感谢 !!
编辑:问题出在 security_check 功能。我想尽可能避免sql注入,所以我做了这个:
function security_checkinput ($s)
{
$s = stripslashes($s);
if (!is_numeric($s))
$s = "'".addslashes($s)."'";
return $s;
}