PHP - mysqli_real_escape_string () espera exactamente 2 parámetros

 
Vista:
Imágen de perfil de alberto
Val: 41
Ha aumentado su posición en 6 puestos en PHP (en relación al último mes)
Gráfica de PHP

mysqli_real_escape_string () espera exactamente 2 parámetros

Publicado por alberto (15 intervenciones) el 21/03/2019 18:32:37
Buenas tardes comunidad tengo una inquietud tengo estos este error

Advertencia : mysqli_real_escape_string () espera exactamente 2 parámetros, 1 en /home/u195606881/public_html/_product-add.php en la línea 10

Advertencia : mysqli_real_escape_string () espera exactamente 2 parámetros, 1 en / home / u195606881 / public_html / -add.php en la línea 10 La columna 'nombre_producto' no puede ser nula

Este es el código con el cual estoy trabajando no se que estoy haciendo mal,cabe aclara que utilizando mysql si me sirve sabiendo que ya esta obsoleto y se utilizo ahora mysqli me sale el error

Mi conexión a la base de datos es $cn;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?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("mysqli_real_escape_string") ? mysqli_real_escape_string( $theValue) : mysqli_escape_string($cn, $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;
 
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro
Val: 1.634
Plata
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

mysqli_real_escape_string () espera exactamente 2 parámetros

Publicado por Alejandro (840 intervenciones) el 21/03/2019 20:59:02
  • Alejandro se encuentra ahora conectado en el
  • chat de PHP
1
$theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($cn, $theValue) : mysqli_escape_string($cn, $theValue);
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de alberto
Val: 41
Ha aumentado su posición en 6 puestos en PHP (en relación al último mes)
Gráfica de PHP

mysqli_real_escape_string () espera exactamente 2 parámetros

Publicado por alberto (15 intervenciones) el 21/03/2019 23:38:48
Alejandro gracias ya lo había hecho como usted me aconseja pero no me sirvió,revisando mi código implementado anteriormente con mysql me servia y ya supe porque la función ahora que esta abajo es mysql trabaja así


1
2
3
4
5
6
7
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") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

y esta es la función que trabaja con mysqli se ve que la condición trabajaba diferente

1
2
3
4
5
6
7
8
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("mysqli_real_escape_string") ? mysqli_real_escape_string($theValue) :mysqli_escape_string($theValue);
  }


Agradezco de todas maneras su atención.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar