I have viewed so many people having this same problem but none of the solutions are relevant / they didn't work.
Firstly, here's my simple code to make things easy:
<?php
$mysqli = new mysqli("localhost", "root", "", "pembsweb");
if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}
function mysqli_secure($string) {
        $string = htmlspecialchars($string);
        $string = trim($string);
        if (get_magic_quotes_gpc()) {
            $string = stripslashes($string);
        }
        $string = $mysqli->real_escape_string($string);
    return $string;
}
echo mysqli_secure("lets\\test//this");
?>
This causes the error:
Fatal error: Call to a member function real_escape_string() on a non-object on line 13
I'm feeling really stupid and irritated right now.. Can anyone help me?
EDIT: I have tried removing all other lines from the function, so all it's doing is the mysqli real escape, and still nothing.. I have also tried defining $string via $string = new stdClass(); on the first line of the function, and still nothing..
 
    