1
I am trying to convert a function to Mysqli, to use with PHP7.1. I am having difficulties with mysqli_real_escape_string, and mysqli_escape_string.
Error:
Notice: Undefined variable: mysqli in config.php on line 16
Warning: mysqli_escape_string() expects Parameter 1 to be mysqli, null Given in > config.php on line 16
CONFIG.PHP FILE
require_once('Connections/conexao.php');
$mysqli = new mysqli($hostname_conexao,$username_conexao,$password_conexao,$database_conexao); if($mysqli->connect_error){echo "Erro";exit();}
if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
        if (PHP_VERSION < 6) {
            $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
        }
        $theValue = function_exists("mysql_real_escape_string") ? mysqli_real_escape_string($mysqli, $theValue) : mysqli_escape_string($mysqli, $theValue);
        switch ($theType) {
            case "text":
                $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
                break;
            case "long":
            case "int":
                $theValue = ($theValue != "") ? intval($theValue) : "NULL";
                break;
            case "double":
                $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
                break;
            case "date":
                $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
                break;
            case "defined":
                $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
                break;
        }
        return $theValue;
    }
}
What I need to do?
I saw the misspelling, but the error continues.
– Tiago
Before performing the function, check the value of
$theValue.– Francisco
I use the function at the time of registering and updating the table like this
GetSQLValueString($_POST['kg'], "text"),.– Tiago
I edited my answer, see if it works now.
– Francisco