Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/07/2013, 07:00
rufus
 
Fecha de Ingreso: mayo-2009
Ubicación: Andalucia
Mensajes: 650
Antigüedad: 15 años, 10 meses
Puntos: 1
problema con insertar registro en mysql con php

que tengo una tabla = "foto" con llos campos id,archivo,tipo,peso,titulo.

pero no se por que se me agregan dos campos mas(dos arrays de errores).

aqui el error: No se ha podido realizar la consultaUnknown column 'errores' in 'field list'
Ultima consulta sql:INSERT INTO foto(id,archivo,tipo,peso,titulo,errores,errores_u pload ) VALUES ('','Hydrangeas.jpg','image/jpeg','595284','','Array','Array')

php del formulario:

Código PHP:
Ver original
  1. <form action="formulario.php" method="post" enctype="multipart/form-data">
  2.         <table>
  3.         <!--     <tr>
  4.                 <td>autor:</td>
  5.                 <td><input type="text" name="autor" /></td>
  6.             </tr>
  7.             <tr>
  8.                 <td>titulo:</td>
  9.                 <td><input type="text" name="titulo" /></td>
  10.             </tr>
  11.             <tr>
  12.                 <td>precio:</td>
  13.                 <td><input type="text" name="precio" /></td>
  14.             </tr>
  15.  -->
  16.              <tr>
  17.              
  18.                 <td><input type="hidden" name="MAX_FILE_SIZE" value="1000000" /></td>
  19.             </tr>
  20.  
  21.                <tr>
  22.                 <td>archivo:</td>
  23.                 <td><input type="file" name="file_upload"  /></td>
  24.             </tr>
  25.  
  26.  
  27.             <tr>
  28.                 <td>titulo imagen</td>
  29.                 <td><input type="text" name="titulo" value="" /></td>
  30.             </tr>
  31.  
  32.         </table>
  33.         <input type="submit" name="submit" value="Ingresar" />
  34.         </form>
  35.      </td>
  36.     </tr>
  37.   </table>

codigo php que procesa el insertado.

Código PHP:
Ver original
  1. <?php
  2. class Foto extends tabla
  3. {
  4.  
  5.    
  6.     public $id;
  7.     public $archivo;
  8.     public $tipo;
  9.     public $peso;
  10.     public $titulo;
  11.     private $nombre_tmp;
  12.     private $fotos_dir ="images";
  13.  
  14.     public $errores = array();
  15.     public $errores_upload = array(
  16.             UPLOAD_ERR_OK => "no se ha producido ningún error",
  17.             UPLOAD_ERR_INI_SIZE =>"El tamaño de archivo ha excedido el maximo indicando en php.ini",
  18.             UPLOAD_ERR_FORM_SIZE => "El tamañode archivo ha excedido el maximo para este formulario",
  19.             UPLOAD_ERR_PARTIAL => "El archivo ha sido subido parcialmente",
  20.             UPLOAD_ERR_NO_FILE=> "el archivo no existe",
  21.             UPLOAD_ERR_NO_TMP_DIR=>"El directorio temporal no existe",
  22.             UPLOAD_ERR_CANT_WRITE=> "No se puede escribir en el disco duro",
  23.             UPLOAD_ERR_EXTENSION=> "Error en una extensión php");
  24.  
  25.  
  26.     protected static $nombre_tabla = "foto";
  27.     protected static $campos_tabla = array("archivo", "tipo","peso","titulo");
  28.  
  29.  
  30.     public function adjuntar_foto($info)
  31.     {
  32.         if(!$info || empty($info) || !is_array($info))
  33.         {
  34.             array_push($errores,"no se a pasado ninguna informacion de archivo.");
  35.             return false;
  36.  
  37.         }
  38.         elseif ($info["error"] != 0)
  39.         {
  40.             array_push($errores,$errores_upload[$info["error"]]);
  41.             return false;
  42.         }
  43.         else
  44.         {
  45.         $this->archivo = basename($info["name"]);
  46.         $this->peso = $info["size"];
  47.         $this->tipo = $info["type"];
  48.         $this->nombre_tmp = $info["tmp_name"];
  49.         return true;
  50.        
  51.         }
  52.     }
  53.  
  54.  
  55.  
  56.     public function guardar()
  57.         {
  58.             if(!isset($this->id))
  59.             {
  60.                 if(!empty($this->errores))
  61.                 {
  62.                     return false;
  63.                 }
  64.  
  65.                 if(strlen($this->titulo) > 255)
  66.                 {
  67.                     $this->errores[] = "El titulo posee más de 255 caracteres";
  68.                     return false;
  69.                 }
  70.                 $nueva_ruta = RAIZ_DIR.SD."public".SD.$this->fotos_dir.SD.$this->archivo;
  71.  
  72.                 if(empty($this->nombre_tmp))
  73.                 {
  74.                     $this->errores[] = "No se tienen los datos suficientes";
  75.                     return false;
  76.  
  77.                 }
  78.  
  79.                 if(file_exists($nueva_ruta))
  80.                 {
  81.                     $this->errores[] = "No se puede utilizar ese nombre de archivo";
  82.                     return false;
  83.                 }
  84.                 if(move_uploaded_file($this->nombre_tmp,$nueva_ruta))
  85.                 {
  86.                     if($this->crear())
  87.                     {
  88.                         return true;
  89.  
  90.                     }
  91.                     else
  92.                     {
  93.                         return false;
  94.                         $this->errores[ ] = "No se ha podido crear el registro en la base de datos";
  95.                     }
  96.                 }
  97.                     else
  98.                     {
  99.                         $this->errores[] = "No se ha podido mover el archivo subido a una ubicación segura.";
  100.                         return false;
  101.                     }
  102.                
  103.            
  104.                }
  105.             else
  106.             {
  107.                 $this->actualizar();
  108.             }
  109.         }
  110.    
  111.  
  112. }
  113.  
  114. ?>