Ver Mensaje Individual
  #13 (permalink)  
Antiguo 31/07/2014, 20:40
nimaki25
 
Fecha de Ingreso: noviembre-2010
Mensajes: 131
Antigüedad: 13 años, 4 meses
Puntos: 1
Respuesta: parametros en consulta Insert PDO

gracias de nuevo, se que soy bastant rompe pero me tiene sacado este tema ejeje, mira en un archivo funciones (donde tengo la conexion y eso), uso esta funcion, la cual me hace insert de todos los campos pero en las imagenes no trabaja (me deja todo null):
Código PHP:
function insertarAvisos(){
            
$this->rutas=array();
          
            try{
                
$query  ="INSERT INTO avisos (titulo_aviso,categoria_aviso,tipo_aviso,comuna,aviso_completo,valor_producto,fecha_publicacion,nombre,telefono_celular,telefono_fijo,correo_electronico,direccion,img1,img2,img3,img4,img5)"//,img1,img2,img3,img4,img5 
                
$query .="VALUES(:titulo_aviso,:categoria_aviso,:tipo_aviso,:comuna,:aviso_completo,:valor_producto,:fecha_publicacion,:nombre,:telefono_celular,:telefono_fijo,:correo_electronico,:direccion,:rutas[0],:rutas[1],:rutas[2],:rutas[3],:rutas[4])"//,:rutas[0],:rutas[1],:rutas[2],:rutas[3],:rutas[4]
                //Preparamos la consulta
                
$stmt$this->con->prepare($query);
                
$stmt->bindParam(':titulo_aviso',$_POST['titulo_aviso'],PDO::PARAM_STR);
                
$stmt->bindParam(':categoria_aviso'$_POST['categoria_aviso'] ,PDO::PARAM_STR);
                
$stmt->bindParam(':tipo_aviso'$_POST['tipo_aviso'] ,PDO::PARAM_STR);
                
$stmt->bindParam(':comuna'$_POST['comuna'],PDO::PARAM_STR);
                
$stmt->bindParam(':aviso_completo'$_POST['aviso_completo'],PDO::PARAM_STR);
                
$stmt->bindParam(':valor_producto'$_POST['valor_producto']);
                
//Fecha de Publicacion
                
$stmt->bindParam(':fecha_publicacion',date('Y-m-d'time()),PDO::PARAM_STR);
                
$stmt->bindParam(':nombre'$_POST['nombre'] ,PDO::PARAM_STR);
                
$stmt->bindParam(':telefono_celular'$_POST['telefono_celular']);
                
$stmt->bindParam(':telefono_fijo'$_POST['telefono_fijo']);
                
$stmt->bindParam(':correo_electronico'$_POST['correo_electronico'] ,PDO::PARAM_STR);
                
$stmt->bindParam(':direccion'$_POST['direccion'] ,PDO::PARAM_STR);

                
$stmt->bindParam(':img1'$this->rutas[0]); //, $this->rutas[0]
                
$stmt->bindParam(':img2'$this->rutas[1]);
                
$stmt->bindParam(':img3'$this->rutas[2]);
                
$stmt->bindParam(':img4'$this->rutas[3]);
                
$stmt->bindParam(':img5'$this->rutas[4]);

                
//Ejecutamos la Consulta
                
$stmt->execute();
                echo 
"Aviso Insertado con Exito en la Base de Datos";

                }catch(
PDOException $e){
                       echo 
$e->errorInfo;
                }
  
        }
//funcion InsertarAvisos 
y el archivo que procesa (el que llamo desde el formulario) es este:
Código PHP:
require_once '../Inc/funciones.php';

$obj = new Avisos();

/*$obj->insertarAvisos();*/


if(isset($_POST['enviar'])){
    
    if(isset(
$_FILES['fotosavisos'])){
        
        
$rutas = array(''''); // Inicializas con dos rutas vacías
             //Subida de Archivos
            
foreach($_FILES['fotosavisos']['tmp_name'] as $key => $nombresTemporal)
            {     
//Nombre del Arreglo generado con el input fotosavisos
                
$nombres=$_FILES['fotosavisos']['name'][$key];
                
//Nombre Temporal de la Imagen (Generada por el servidor)
                
$nombresTemporal=$_FILES['fotosavisos']['tmp_name'][$key];
                        
//Tamaño de la Imagen
                
$tamaño=$_FILES['fotosavisos']['size'][$key];
                        
//Tipo de Imagen
                
$tipo=$_FILES['fotosavisos']['type'][$key];
               
                
//Ruta en Servidor
                
$rutaFinal="../imagenes_avisos/".$nombres;

            
//Movemos los Archivos al Servidor
            
move_uploaded_file($nombresTemporal,$rutaFinal);
              
            
// Actualizas la ruta correspondiente para este archivo
            
$rutas[$key] = $rutaFinal;

        }
//foreach  
        
                    
            
//Llamamos a la funcion Insertar $obj->insertarAvisos();
        
    
try{
            
print_r($_POST);
    }catch(
PDOException $e){
        echo 
$e;
    }
        
    }