简体   繁体   中英

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.

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?

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:

global $con = mysqli_connect();

or you need to pass $con as an argument:

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; as the first line in your function. – Mihai

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM