[英]mysqli_real_escape_string mysqli link?
I get "Notice: Undefined variable: con in C:\\wamp\\www\\Game\\functions.php on line 8" when trying to use the function, here's the code. 尝试使用该函数时,出现“ Notice:Undefined variable:con in C:\\ wamp \\ www \\ Game \\ functions.php在第8行”,这是代码。
function protect($string) {
return mysqli_real_escape_string($con,strip_tags(addslashes($string)));
}
I use the $con for my queries and it's fine so I thought that was what was for this mysqli part? 我使用$ con进行查询,这很好,所以我认为那是mysqli部分的内容?
This is for registration, I have some registration that is working but I can't use that, here's a confirmed working line 这是用于注册,我有一些正在运行的注册,但是我不能使用,这是已确认的工作热线
$res=mysqli_query($con,$sql);
Any ideas? 有任何想法吗?
$con
doesn't exist in the function protect()
, so you either need to make $con
global: $con
在函数protect()
中不存在,因此您需要使$con
全局变量:
global $con = mysqli_connect();
or you need to pass $con
as an argument: 或者您需要传递
$con
作为参数:
function protect($string, $con) {
return mysqli_real_escape_string($con,strip_tags(addslashes($string)));
}
ANSWER FROM MIHAI 来自密海的答案
mysqli_real_escape_string needs a connection BEFORE it can function,use global $con; mysqli_real_escape_string需要先建立连接,然后才能使用全局$ con; as the first line in your function.
作为函数的第一行。 – Mihai
–米海
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.