mysqli_real_escape_string ()

2

Could you help me with this error?

  

mysqli_real_escape_string () expects parameter 1 to be mysqli, null given

<?php require_once('../Connections/catalogo.php'); ?>
<?php
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($Catalogo, $theValue): mysqli_escape_string($theValue);
// : mysql_escape_string($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;
}
}
?>
    
asked by Javier Joasimar Palos Flores 07.01.2017 в 04:57
source

2 answers

0

mysqli_real_escape_string() expects parameter 1 to be mysqli, null given when called as a function, the first parameter must be a variable that is declared as $conexion = new mysqli(.....);

in your if you have

$theValue = function_exists("mysql_real_escape_string") ? mysqli_real_escape_string($Catalogo, $theValue): mysqli_escape_string($theValue);

but inside the function you do not know who is $Catalogo , you can pass it as a parameter

    
answered by 07.01.2017 в 07:48
0

I solved it in this way.

After the next line:

 if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

I've inserted this IF:

 if (PHP_VERSION >= 7) {     // SI la versión de PHP es mayor o igual a 7.
    global $Catalogo;        // Hago global la variable 
  }

That was enough.

    
answered by 03.11.2017 в 17:58