Foros del Web » Programando para Internet » PHP »

error de parse

Estas en el tema de error de parse en el foro de PHP en Foros del Web. Hola a todos!, les cuento: tengo una base de datos con 300 campos en mysql, para ello necesito insertar datos via formulario, por eso he ...
  #1 (permalink)  
Antiguo 18/02/2004, 11:47
Avatar de andinistas  
Fecha de Ingreso: julio-2003
Ubicación: Bogotá COL
Mensajes: 1.000
Antigüedad: 14 años, 4 meses
Puntos: 0
Pregunta error de parse

Hola a todos!, les cuento:

tengo una base de datos con 300 campos en mysql, para ello necesito insertar datos via formulario, por eso he estructurado mi form en 4 partes (parte1.php -- parte4.php) y el procesamiento del form en el archivo send1.php, todo esto lo manejo con sesiones, pero al momento de procesar el formulario insertandolo en la base de datos obtendo el error de parse al intentar hacer un implode de un array, mi codigo aqui

Código PHP:
session_start();
// Sumo el array que ya tengo del anterior formulario con el que generé en el formulario que estoy procesando ...

// El mismo proceso es igual para N formularios que pueda tener ..
$_SESSION['variables']=array_merge($_SESSION['variables'],$_POST);

$variables=$_SESSION['variables'];

$tipodevalor = array (
    
"fecharegistro" => "DATE",
    
"departamento" => "VARCHAR",
    
"dos" => "VARCHAR",
    
"ciudad" => "VARCHAR",
    
"ciudaddos" => "VARCHAR",
    
"a01" => "VARCHAR",
    
"a02" => "VARCHAR",
    
"a03" => "VARCHAR",
    
"a04" => "VARCHAR",
    
"fechades" => "DATE",
    
"fecharet" => "DATE",
    
"a05" => "TEXT",
    
"a06"  => "CHAR",
    
"a07" => "CHAR",
    
"a08" => "CHAR",
    
"a09" => "CHAR",
    
"a10" => "CHAR",
    
"a11" => "CHAR",
    
"a12" => "CHAR",
    
"a13" => "CHAR",
    
"a14" => "CHAR",
    
"a15" => "CHAR",
    
"a16" => "CHAR",
    
"a17" => "CHAR",
    
"a18" => "CHAR",
    
"a19" => "CHAR",
    
"a20" => "CHAR",
    
"a21" => "VARCHAR",
    
"a22" => "CHAR",
    
"a23" => "CHAR",
    
"a24" => "CHAR",
    
"a25" => "CHAR",
    
"a26" => "VARCHAR",
    
"a27" => "CHAR",
    
"a28" => "VARCHAR",
    
"a29" => "CHAR",
    
"a30" => "VARCHAR",
    
"a31" => "CHAR",
    
"a32" => "VARCHAR",
    
"a33" => "CHAR",
    
"a34" => "VARCHAR",
    
"a35" => "VARCHAR",
    
"a36" => "VARCHAR",
    
"a37" => "VARCHAR",
    
"a38" => "VARCHAR",
    
"a39" => "VARCHAR",
    
"a40" => "VARCHAR",
    
"a41" => "VARCHAR",
    
"a42" => "VARCHAR",
    
"a43" => "VARCHAR",
    
"a44" => "VARCHAR",
    
"a45" => "VARCHAR",
    
"a46" => "TEXT",
    
"b01" => "CHAR",
    
"b02" => "CHAR",
    
"b03" => "CHAR",
    
"b04" => "CHAR",
    
"b05" => "CHAR",
    
"b06" => "CHAR",
    
"b07" => "TEXT",
    
"b08" => "CHAR",
    
"b09" => "CHAR",
    
"b10" => "TEXT",
    
"b11" => "CHAR",
    
"b12" => "CHAR",
    
"b13" => "CHAR",
    
"b14" => "CHAR",
    
"b15" => "CHAR",
    
"b16" => "CHAR",
    
"b17" => "CHAR",
    
"b18" => "CHAR",
    
"b19" => "CHAR",
    
"b20" => "CHAR",
    
"b21" => "CHAR",
    
"b22" => "CHAR",
    
"b23" => "VARCHAR",
    
"b24" => "VARCHAR",
    
"b25" => "VARCHAR",
    
"b26" => "VARCHAR",
    
"b27" => "VARCHAR",
    
"b28" => "VARCHAR",
    
"b29" => "VARCHAR",
    
"b30" => "VARCHAR",
    
"b31" => "VARCHAR",
    
"b32" => "VARCHAR",
    
"b33" => "VARCHAR",
    
"b34" => "VARCHAR",
    
"b35" => "VARCHAR",
    
"b36" => "VARCHAR",
    
"b37" => "VARCHAR",
    
"b38" => "VARCHAR",
    
"b39" => "VARCHAR",
    
"b40" => "VARCHAR",
    
"b41" => "VARCHAR",
    
"b42" => "VARCHAR",
    
"b43" => "VARCHAR",
    
"b44" => "VARCHAR",
    
"b45" => "VARCHAR",
    
"b46" => "VARCHAR",
    
"b47" => "VARCHAR",
    
"b48" => "VARCHAR",
    
"b49" => "VARCHAR",
    
"b50" => "VARCHAR",
    
"b51" => "VARCHAR",
    
"b52" => "VARCHAR",
    
"b53" => "VARCHAR",
    
"b54" => "VARCHAR",
    
"b55" => "VARCHAR",
    
"b56" => "VARCHAR",
    
"b57" => "VARCHAR",
    
"b58" => "VARCHAR",
    
"b59" => "VARCHAR",
    
"b60" => "VARCHAR",
    
"b61" => "VARCHAR",
    
"b62" => "VARCHAR",
    
"b63" => "VARCHAR",
    
"b64" => "VARCHAR",
    
"b65" => "VARCHAR",
    
"b66" => "VARCHAR",
    
"b67" => "TEXT",
    
"b68" => "CHAR",
    
"b69" => "CHAR",
    
"b70" => "TEXT",
    
"c01" => "CHAR",
    
"c02" => "VARCHAR",
    
"c03" => "VARCHAR",
    
"c04" => "VARCHAR",
    
"c05" => "VARCHAR",
    
"c06" => "VARCHAR",
    
"c07" => "VARCHAR",
    
"c08" => "CHAR",
    
"c09" => "VARCHAR",
    
"c10" => "VARCHAR",
    
"c11" => "VARCHAR",
    
"c12" => "VARCHAR",
    
"c13" => "VARCHAR",
    
"c14" => "VARCHAR",
    
"c15" => "CHAR",
    
"c16" => "VARCHAR",
    
"c17" => "VARCHAR",
    
"c18" => "VARCHAR",
    
"c19" => "VARCHAR",
    
"c20" => "VARCHAR",
    
"c21" => "VARCHAR",
    
"c22" => "CHAR",
    
"c23" => "VARCHAR",
    
"c24" => "VARCHAR",
    
"c25" => "VARCHAR",
    
"c26" => "VARCHAR",
    
"c27" => "VARCHAR",
    
"c28" => "VARCHAR",
    
"c29" => "CHAR",
    
"c30" => "VARCHAR",
    
"c31" => "VARCHAR",
    
"c32" => "VARCHAR",
    
"c33" => "VARCHAR",
    
"c34" => "VARCHAR",
    
"c35" => "VARCHAR",
    
"c36" => "VARCHAR",
    
"c37" => "VARCHAR",
    
"c38" => "VARCHAR",
    
"c39" => "VARCHAR",
    
"c40" => "VARCHAR",
    
"c41" => "VARCHAR",
    
"c42" => "VARCHAR",
    
"c43" => "VARCHAR",
    
"c44" => "VARCHAR",
    
"c45" => "VARCHAR",
    
"c46" => "VARCHAR",
    
"c47" => "VARCHAR",
    
"c48" => "VARCHAR",
    
"c49" => "VARCHAR",
    
"c50" => "VARCHAR",
    
"c51" => "VARCHAR",
    
"c52" => "VARCHAR",
    
"c53" => "VARCHAR",
    
"c54" => "VARCHAR",
    
"c55" => "VARCHAR",
    
"c56" => "VARCHAR",
    
"c57" => "VARCHAR",
    
"c58" => "VARCHAR",
    
"c59" => "VARCHAR",
    
"c60" => "VARCHAR",
    
"c61" => "VARCHAR",
    
"c62" => "VARCHAR",
    
"c63" => "VARCHAR",
    
"c64" => "VARCHAR",
    
"c65" => "VARCHAR",
    
"c66" => "CHAR",
    
"c67" => "VARCHAR",
    
"c68" => "CHAR",
    
"c69" => "VARCHAR",
    
"c70" => "CHAR",
    
"c71" => "VARCHAR",
    
"c72" => "CHAR",
    
"c73" => "VARCHAR",
    
"c74" => "CHAR",
    
"c75" => "VARCHAR",
    
"c76" => "CHAR",
    
"c77" => "VARCHAR",
    
"c78" => "TEXT",
    
"c79" => "VARCHAR",
    
"c80" => "VARCHAR",
    
"c81" => "VARCHAR",
    
"c82" => "VARCHAR",
    
"c83" => "VARCHAR",
    
"c84" => "VARCHAR",
    
"c85" => "VARCHAR",
    
"c86" => "VARCHAR",
    
"c87" => "VARCHAR",
    
"c88" => "VARCHAR",
    
"c89" => "VARCHAR",
    
"c90" => "VARCHAR",
    
"c91" => "VARCHAR",
    
"c92" => "VARCHAR",
    
"c93" => "VARCHAR",
    
"c94" => "VARCHAR",
    
"c95" => "VARCHAR",
    
"c96" => "VARCHAR",
    
"c97" => "VARCHAR",
    
"c98" => "VARCHAR",
    
"c99" => "VARCHAR",
    
"c100" => "VARCHAR",
    
"c101" => "VARCHAR",
    
"c102" => "VARCHAR",
    
"c103" => "VARCHAR",
    
"c104" => "VARCHAR",
    
"c105" => "VARCHAR",
    
"c106" => "VARCHAR",
    
"c107" => "VARCHAR",
    
"c108" => "VARCHAR",
    
"c109" => "VARCHAR",
    
"c110" => "VARCHAR",
    
"c111" => "TEXT",
    
"c112" => "TEXT",
    
"c113" => "TEXT",
    
"c114" => "TEXT",
    
"c115" => "TEXT",
    
"d01" => "VARCHAR"
    
"d02" => "VARCHAR"
    
"d03" => "VARCHAR"
    
"d04" => "VARCHAR"
    
"d05" => "VARCHAR"
    
"d06" => "VARCHAR"
    
"d07" => "VARCHAR"
    
"d08" => "VARCHAR",     
    
"d09" => "VARCHAR"
    
"d10" => "VARCHAR"
    
"d11" => "VARCHAR"
    
"d12" => "VARCHAR"
    
"d13" => "VARCHAR"
    
"d14" => "VARCHAR"
    
"d15" => "VARCHAR"
    
"d16" => "VARCHAR"
    
"d17" => "VARCHAR"
    
"d18" => "VARCHAR"
    
"d19" => "VARCHAR"
    
"d20" => "VARCHAR"
    
"d21" => "VARCHAR"
    
"d22" => "VARCHAR"
    
"d23" => "VARCHAR"
    
"d24" => "VARCHAR"
    
"d25" => "VARCHAR"
    
"d26" => "VARCHAR"
    
"d27" => "VARCHAR"
    
"d28" => "VARCHAR"
    
"d29" => "VARCHAR"
    
"d30" => "VARCHAR"
    
"d31" => "VARCHAR"
    
"d32" => "VARCHAR"
    
"d33" => "VARCHAR"
    
"d34" => "VARCHAR"
    
"d35" => "VARCHAR"
    
"d36" => "VARCHAR"
    
"d37" => "VARCHAR"
    
"d38" => "VARCHAR"
    
"d39" => "VARCHAR"
    
"d40" => "VARCHAR"
    
"d41" => "VARCHAR"
    
"d42" => "VARCHAR"
    
"d43" => "VARCHAR"
    
"d44" => "VARCHAR"
    
"d45" => "TEXT",
    
"d46" => "CHAR",
    
"d47" => "CHAR",
    
"d48" => "CHAR",
    
"d49" => "CHAR",
    
"d50" => "CHAR",
    
"d51" => "CHAR",
    
"d52" => "CHAR",
    
"d53" => "CHAR",
    
"d54" => "CHAR",
    
"d55" => "CHAR",
    
"d56" => "TEXT",
    
"d57" => "VARCHAR"
    
"d58" => "TEXT",
    
"d59" => "VARCHAR"
    
"d60" => "TEXT",
    
"d61" => "TEXT",
    
"d62" => "VARCHAR"
    
"d63" => "TEXT",
    
"d64" => "TEXT",
    
"d65" => "TEXT");

// Entonces, al llegar a la asignacion del valor, comparas el campo
// y determinas como lo vas a insertar...

$variables=$_SESSION['variables'];
foreach (
$variables as $campo => $valor) {
    
$campos[]=$campo;
    switch (
$tipodevalor[$campo]) {
        case 
"VARCHAR":
        
$valores[]= "'".$valor."'";
        break;
        case 
"CHAR":
        
$valores[]= "'".$valor."'";
        break;
        case 
"TEXT":
        
$valores[]= $valor;
        break;
        case 
"DATE":
        
$valores[]= "'".$valor."'";
        break;
        default:  
//Por si alguno se te olvida
        
$valores[]= "'".$valor."'";
        break;
    }
}

// el error esta aqui
sql="INSERT INTO tabla (implode(",",$campos)) VALUES (implode(",",$valores))";

mysql_query($sql) or die("Error en consulta <br>MySQL dice: ".mysql_error());
echo 
"Los Datos han sido ingresados correctamente!";
?> 
  #2 (permalink)  
Antiguo 18/02/2004, 15:42
Ex Colaborador
 
Fecha de Ingreso: junio-2002
Mensajes: 9.091
Antigüedad: 15 años, 5 meses
Puntos: 16
Hola,

Las funciones no se pueden meter dentro de una cadena, deben concatenarse.

Saludos.
__________________
Josemi

Aprendiz de mucho, maestro de poco.
  #3 (permalink)  
Antiguo 18/02/2004, 16:48
Avatar de andinistas  
Fecha de Ingreso: julio-2003
Ubicación: Bogotá COL
Mensajes: 1.000
Antigüedad: 14 años, 4 meses
Puntos: 0
y como hago?

Hola josemi, me podrias explicar como hacer para concatenar la funcion que tengo?



salu2
  #4 (permalink)  
Antiguo 18/02/2004, 18:40
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 15 años, 11 meses
Puntos: 126
Sería algo así:

Código PHP:
$sql="INSERT INTO tabla (".implode(",",$campos).") VALUES (".implode(",",$valores).")"
Fijate como cambia la cosa al usar la concatenación (el . punto) y como PHP lo colorea distinto ...

más info en:
http://www.php.net/manual/en/languag...ors.string.php


Un saludo,
__________________
Por motivos personales ya no puedo estar con Uds. Fue grato haber compartido todos estos años. Igualmente los seguiré leyendo.
  #5 (permalink)  
Antiguo 19/02/2004, 09:58
Avatar de andinistas  
Fecha de Ingreso: julio-2003
Ubicación: Bogotá COL
Mensajes: 1.000
Antigüedad: 14 años, 4 meses
Puntos: 0
Funciono!

Hola cluster, josemi y demas colaboradores, me funcionó el script al principio tenia en los bontones name=enviar lo que me daba un error en la consulta sql porque no habia ninguna columna con ese nombre, total le quite esa propiedad a los botones.

el codigo correcto es


Código PHP:
session_start();
// Sumo el array que ya tengo del anterior formulario con el que generé en el formulario que estoy procesando ...

// El mismo proceso es igual para N formularios que pueda tener ..
$_SESSION['variables']=array_merge($_SESSION['variables'],$_POST);

$variables=$_SESSION['variables'];


//especifico las propiedades de cada campo
$tipodevalor = array (
    
"fecharegistro" => "DATE",
    
"departamento" => "VARCHAR",
    
"dos" => "VARCHAR",
    
"ciudad" => "VARCHAR",
    
"ciudaddos" => "VARCHAR",
    
"a01" => "VARCHAR",
    
"a02" => "VARCHAR",
    
"a03" => "VARCHAR",
    
"a04" => "VARCHAR",
    
"fechades" => "DATE",
    
"fecharet" => "DATE",
    
"a05" => "TEXT",
    
"a06"  => "CHAR",
    
"a07" => "CHAR",
    
"a08" => "CHAR",
    
"a09" => "CHAR",
    
"a10" => "CHAR",
    
"a11" => "CHAR",
    
"a12" => "CHAR",
    
"a13" => "CHAR",
    
"a14" => "CHAR",
    
"a15" => "CHAR",
    
"a16" => "CHAR",
    
"a17" => "CHAR",
    
"a18" => "CHAR",
    
"a19" => "CHAR",
    
"a20" => "CHAR",
    
"a21" => "VARCHAR",
    
"a22" => "CHAR",
    
"a23" => "CHAR",
    
"a24" => "CHAR",
    
"a25" => "CHAR",
    
"a26" => "VARCHAR",
    
"a27" => "CHAR",
    
"a28" => "VARCHAR",
    
"a29" => "CHAR",
    
"a30" => "VARCHAR",
    
"a31" => "CHAR",
    
"a32" => "VARCHAR",
    
"a33" => "CHAR",
    
"a34" => "VARCHAR",
    
"a35" => "VARCHAR",
    
"a36" => "VARCHAR",
    
"a37" => "VARCHAR",
    
"a38" => "VARCHAR",
    
"a39" => "VARCHAR",
    
"a40" => "VARCHAR",
    
"a41" => "VARCHAR",
    
"a42" => "VARCHAR",
    
"a43" => "VARCHAR",
    
"a44" => "VARCHAR",
    
"a45" => "VARCHAR",
    
"a46" => "TEXT",
    
"b01" => "CHAR",
    
"b02" => "CHAR",
    
"b03" => "CHAR",
    
"b04" => "CHAR",
    
"b05" => "CHAR",
    
"b06" => "CHAR",
    
"b07" => "TEXT",
    
"b08" => "CHAR",
    
"b09" => "CHAR",
    
"b10" => "TEXT",
    
"b11" => "CHAR",
    
"b12" => "CHAR",
    
"b13" => "CHAR",
    
"b14" => "CHAR",
    
"b15" => "CHAR",
    
"b16" => "CHAR",
    
"b17" => "CHAR",
    
"b18" => "CHAR",
    
"b19" => "CHAR",
    
"b20" => "CHAR",
    
"b21" => "CHAR",
    
"b22" => "CHAR",
    
"b23" => "VARCHAR",
    
"b24" => "VARCHAR",
    
"b25" => "VARCHAR",
    
"b26" => "VARCHAR",
    
"b27" => "VARCHAR",
    
"b28" => "VARCHAR",
    
"b29" => "VARCHAR",
    
"b30" => "VARCHAR",
    
"b31" => "VARCHAR",
    
"b32" => "VARCHAR",
    
"b33" => "VARCHAR",
    
"b34" => "VARCHAR",
    
"b35" => "VARCHAR",
    
"b36" => "VARCHAR",
    
"b37" => "VARCHAR",
    
"b38" => "VARCHAR",
    
"b39" => "VARCHAR",
    
"b40" => "VARCHAR",
    
"b41" => "VARCHAR",
    
"b42" => "VARCHAR",
    
"b43" => "VARCHAR",
    
"b44" => "VARCHAR",
    
"b45" => "VARCHAR",
    
"b46" => "VARCHAR",
    
"b47" => "VARCHAR",
    
"b48" => "VARCHAR",
    
"b49" => "VARCHAR",
    
"b50" => "VARCHAR",
    
"b51" => "VARCHAR",
    
"b52" => "VARCHAR",
    
"b53" => "VARCHAR",
    
"b54" => "VARCHAR",
    
"b55" => "VARCHAR",
    
"b56" => "VARCHAR",
    
"b57" => "VARCHAR",
    
"b58" => "VARCHAR",
    
"b59" => "VARCHAR",
    
"b60" => "VARCHAR",
    
"b61" => "VARCHAR",
    
"b62" => "VARCHAR",
    
"b63" => "VARCHAR",
    
"b64" => "VARCHAR",
    
"b65" => "VARCHAR",
    
"b66" => "VARCHAR",
    
"b67" => "TEXT",
    
"b68" => "CHAR",
    
"b69" => "CHAR",
    
"b70" => "TEXT",
    
"c01" => "CHAR",
    
"c02" => "VARCHAR",
    
"c03" => "VARCHAR",
    
"c04" => "VARCHAR",
    
"c05" => "VARCHAR",
    
"c06" => "VARCHAR",
    
"c07" => "VARCHAR",
    
"c08" => "CHAR",
    
"c09" => "VARCHAR",
    
"c10" => "VARCHAR",
    
"c11" => "VARCHAR",
    
"c12" => "VARCHAR",
    
"c13" => "VARCHAR",
    
"c14" => "VARCHAR",
    
"c15" => "CHAR",
    
"c16" => "VARCHAR",
    
"c17" => "VARCHAR",
    
"c18" => "VARCHAR",
    
"c19" => "VARCHAR",
    
"c20" => "VARCHAR",
    
"c21" => "VARCHAR",
    
"c22" => "CHAR",
    
"c23" => "VARCHAR",
    
"c24" => "VARCHAR",
    
"c25" => "VARCHAR",
    
"c26" => "VARCHAR",
    
"c27" => "VARCHAR",
    
"c28" => "VARCHAR",
    
"c29" => "CHAR",
    
"c30" => "VARCHAR",
    
"c31" => "VARCHAR",
    
"c32" => "VARCHAR",
    
"c33" => "VARCHAR",
    
"c34" => "VARCHAR",
    
"c35" => "VARCHAR",
    
"c36" => "VARCHAR",
    
"c37" => "VARCHAR",
    
"c38" => "VARCHAR",
    
"c39" => "VARCHAR",
    
"c40" => "VARCHAR",
    
"c41" => "VARCHAR",
    
"c42" => "VARCHAR",
    
"c43" => "VARCHAR",
    
"c44" => "VARCHAR",
    
"c45" => "VARCHAR",
    
"c46" => "VARCHAR",
    
"c47" => "VARCHAR",
    
"c48" => "VARCHAR",
    
"c49" => "VARCHAR",
    
"c50" => "VARCHAR",
    
"c51" => "VARCHAR",
    
"c52" => "VARCHAR",
    
"c53" => "VARCHAR",
    
"c54" => "VARCHAR",
    
"c55" => "VARCHAR",
    
"c56" => "VARCHAR",
    
"c57" => "VARCHAR",
    
"c58" => "VARCHAR",
    
"c59" => "VARCHAR",
    
"c60" => "VARCHAR",
    
"c61" => "VARCHAR",
    
"c62" => "VARCHAR",
    
"c63" => "VARCHAR",
    
"c64" => "VARCHAR",
    
"c65" => "VARCHAR",
    
"c66" => "CHAR",
    
"c67" => "VARCHAR",
    
"c68" => "CHAR",
    
"c69" => "VARCHAR",
    
"c70" => "CHAR",
    
"c71" => "VARCHAR",
    
"c72" => "CHAR",
    
"c73" => "VARCHAR",
    
"c74" => "CHAR",
    
"c75" => "VARCHAR",
    
"c76" => "CHAR",
    
"c77" => "VARCHAR",
    
"c78" => "TEXT",
    
"c79" => "VARCHAR",
    
"c80" => "VARCHAR",
    
"c81" => "VARCHAR",
    
"c82" => "VARCHAR",
    
"c83" => "VARCHAR",
    
"c84" => "VARCHAR",
    
"c85" => "VARCHAR",
    
"c86" => "VARCHAR",
    
"c87" => "VARCHAR",
    
"c88" => "VARCHAR",
    
"c89" => "VARCHAR",
    
"c90" => "VARCHAR",
    
"c91" => "VARCHAR",
    
"c92" => "VARCHAR",
    
"c93" => "VARCHAR",
    
"c94" => "VARCHAR",
    
"c95" => "VARCHAR",
    
"c96" => "VARCHAR",
    
"c97" => "VARCHAR",
    
"c98" => "VARCHAR",
    
"c99" => "VARCHAR",
    
"c100" => "VARCHAR",
    
"c101" => "VARCHAR",
    
"c102" => "VARCHAR",
    
"c103" => "VARCHAR",
    
"c104" => "VARCHAR",
    
"c105" => "VARCHAR",
    
"c106" => "VARCHAR",
    
"c107" => "VARCHAR",
    
"c108" => "VARCHAR",
    
"c109" => "VARCHAR",
    
"c110" => "VARCHAR",
    
"c111" => "TEXT",
    
"c112" => "TEXT",
    
"c113" => "TEXT",
    
"c114" => "TEXT",
    
"c115" => "TEXT",
    
"d01" => "VARCHAR"
    
"d02" => "VARCHAR"
    
"d03" => "VARCHAR"
    
"d04" => "VARCHAR"
    
"d05" => "VARCHAR"
    
"d06" => "VARCHAR"
    
"d07" => "VARCHAR"
    
"d08" => "VARCHAR",     
    
"d09" => "VARCHAR"
    
"d10" => "VARCHAR"
    
"d11" => "VARCHAR"
    
"d12" => "VARCHAR"
    
"d13" => "VARCHAR"
    
"d14" => "VARCHAR"
    
"d15" => "VARCHAR"
    
"d16" => "VARCHAR"
    
"d17" => "VARCHAR"
    
"d18" => "VARCHAR"
    
"d19" => "VARCHAR"
    
"d20" => "VARCHAR"
    
"d21" => "VARCHAR"
    
"d22" => "VARCHAR"
    
"d23" => "VARCHAR"
    
"d24" => "VARCHAR"
    
"d25" => "VARCHAR"
    
"d26" => "VARCHAR"
    
"d27" => "VARCHAR"
    
"d28" => "VARCHAR"
    
"d29" => "VARCHAR"
    
"d30" => "VARCHAR"
    
"d31" => "VARCHAR"
    
"d32" => "VARCHAR"
    
"d33" => "VARCHAR"
    
"d34" => "VARCHAR"
    
"d35" => "VARCHAR"
    
"d36" => "VARCHAR"
    
"d37" => "VARCHAR"
    
"d38" => "VARCHAR"
    
"d39" => "VARCHAR"
    
"d40" => "VARCHAR"
    
"d41" => "VARCHAR"
    
"d42" => "VARCHAR"
    
"d43" => "VARCHAR"
    
"d44" => "VARCHAR"
    
"d45" => "TEXT",
    
"d46" => "CHAR",
    
"d47" => "CHAR",
    
"d48" => "CHAR",
    
"d49" => "CHAR",
    
"d50" => "CHAR",
    
"d51" => "CHAR",
    
"d52" => "CHAR",
    
"d53" => "CHAR",
    
"d54" => "CHAR",
    
"d55" => "CHAR",
    
"d56" => "TEXT",
    
"d57" => "VARCHAR"
    
"d58" => "TEXT",
    
"d59" => "VARCHAR"
    
"d60" => "TEXT",
    
"d61" => "TEXT",
    
"d62" => "VARCHAR"
    
"d63" => "TEXT",
    
"d64" => "TEXT",
    
"d65" => "TEXT");

// Entonces, al llegar a la asignacion del valor, comparo el campo
// y determinas como lo vas a insertar...

$variables=$_SESSION['variables'];
foreach (
$variables as $campo => $valor) {
    
$campos[]=$campo;
    switch (
$tipodevalor[$campo]) {
        case 
"VARCHAR":
        
$valores[]= "'".$valor."'";
        break;
        case 
"CHAR":
        
$valores[]= $valor;
        break;
        case 
"TEXT":
        
$valores[]= "'".$valor."'";
        break;
        case 
"DATE":
        
$valores[]= "'".$valor."'";
        break;
        default:  
//Por si alguno se te olvida
        
$valores[]= "'".$valor."'";
        break;
    }
}

//hago un implode en la consulta sql con el valor de $campos y $valores
$sql="INSERT INTO retornos (".implode(",",$campos).") VALUES (".implode(",",$valores).")";

mysql_query($sql) or die("Error en consulta <br>MySQL dice: ".mysql_error());
echo 
"Los Datos han sido ingresados correctamente!"
ahora me gustaría saber como hago para validar x campos que yo pueda definir



salu2
  #6 (permalink)  
Antiguo 19/02/2004, 15:54
Ex Colaborador
 
Fecha de Ingreso: junio-2002
Mensajes: 9.091
Antigüedad: 15 años, 5 meses
Puntos: 16
Bueno, no es que sea la solucion mas "correcta". Los atributos de los controles de los formularios estan para ponerse. Mejor solucion seria comprobar si el nombre del campo esta en el array de indices:
Código PHP:
foreach ($variables as $campo => $valor) {
     if (!
in_array($campo,array_keys($tipodevalor))) continue;

    
$campos[]=$campo
Saludos.
__________________
Josemi

Aprendiz de mucho, maestro de poco.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:34.