Ver Mensaje Individual
  #2 (permalink)  
Antiguo 07/02/2010, 06:58
Avatar de santris
santris
 
Fecha de Ingreso: agosto-2009
Ubicación: Sant Feliu de Llobregat
Mensajes: 955
Antigüedad: 14 años, 9 meses
Puntos: 66
Respuesta: ayudenme con este error gracias .mysql

Hola,

A ver si te sirve esto, es un ejemplo de dos campos campo1 y campo2 pero lo puedes adaptar a tus necesidades.

Código PHP:
function GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue "")
{
  
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}



$insertSQL sprintf("INSERT INTO tabla (campo1, campo2) VALUES (%s, %s)",
            
GetSQLValueString($_POST['campo1'], "int"),
            
GetSQLValueString($_POST['campo2'], "text"));
if(
mysql_query($insertSQL))
    echo&
#8221;Inserción realizada”; 
Saludos