我有mysqli_real_escape_string()期望参数1是mysqli,在....中给出null。未定义的变量:链接在..... error.i中使用我的代码中的$ link.but我不在哪里我的代码是错误的。 这是我的代码:
function Check_Get($value)
{
include 'connect.php';
$return1 = mysqli_real_escape_string($link,$value);
$return2 = htmlspecialchars($return1);
$return3 = intval($return2);
return $return3;
}
-------------------------------
if(isset($_POST['login'])){
if($_POST['username']=="" || $_POST['password']=="" || $_POST['email']=="")
{
$security->Redirect("index","empty=1020");
}
else{
}
}
-------------------------------
if(isset($_GET['empty']))
{
$security->Check_Get($_GET['empty']);
$template->message("please fill all field","red");
}
-------------------------------
这是我的连接代码:
$Server_name = "localhost";
$Server_username = "root";
$Server_password = "";
$db_name = "news";
$link = mysqli_connect($Server_name,$Server_username,$Server_password) or
exit ("Error in Connection to Server");
if($link)
{
if(mysqli_select_db($link,$db_name))
{
mysqli_query($link,"set names utf8");
mysqli_query($link,"set charset utf8");
$result = mysqli_query($link,$sql);
if(!$result)
{
echo "Error in Query";
}
return $result;
}
else
{
echo "Error in Connection to DataBase";
}
}
else
{
echo "Error in Connection to Server";
}
答案 0 :(得分:2)
我相信您将使用以下内容创建连接对象:
$conn = mysqli_connect();
然后你需要在这里传递该对象:
$user = mysqli_real_escape_string($conn, $user);
我相信你正在使用下面的内容,没有第一个参数:
$user = mysqli_real_escape_string($user);