Ver Mensaje Individual
  #3 (permalink)  
Antiguo 10/07/2008, 11:52
Avatar de [NiRVaNa]
[NiRVaNa]
 
Fecha de Ingreso: abril-2004
Ubicación: Someplace In The Middle Of Nowhere!
Mensajes: 325
Antigüedad: 20 años
Puntos: 6
Exclamación Respuesta: POST se ejecuta al actualizar, ¿como lo evito?

Te paso, solo hago esos 3 inserts porque lo hago por pasos..

Código PHP:
<?php
    
include("lib/class.upload.php");
    
$primerpaso true;
    
$segundopaso false;
        
    if (
$_POST['primero']) {

        
//Manejo para upload de imagenes, y guardar la direccion en la base de datos
        
$handle = new Upload($_FILES['pic']);
    
        
// then we check if the file has been uploaded properly
        // in its *temporary* location in the server (often, it is /tmp)
        
if ($handle->uploaded) {
    
            
// yes, the file is on the server
            // now, we start the upload 'process'. That is, to copy the uploaded file
            // from its temporary location to the wanted location
            // It could be something like $handle->Process('/home/www/my_uploads/');
            
$upload_dir "src/images/products";
            
$handle->Process('../'.$upload_dir);
            
            
// we check if everything went OK
            
if ($handle->processed) {
                
// everything was fine !
                
$image_info $upload_dir.'/'.$handle->file_dst_name;
            } else {
                
// one error occured
                
die ($handle->error);
            }
         
$handle-> Clean();
        }
        if (
$_POST['name'] == "") die("Nombre es un campo requerido");
        
$sql "insert into products (nombre, foto, estado) values ('";
        
$sql .= $_POST['name']."', '";
        
$sql .= $image_info."', 'borrador')";
        if (
mysql_db_query($db$sql$link)) {
            
$primerpaso false;
            
$segundopaso true;
        } else {
            echo 
mysql_error();
        }
    }
?>
y el form es este:

Código HTML:
<form name="products" method="post" action="?do=products&amp;go=alta" enctype="multipart/form-data">
<table width="100%" border="0">
  <tr>
    <th scope="row"><label>Nombre</label></th>
    <td><input type="text" name="name" /></td>
  </tr>
  <tr>
    <th scope="row"><label>Imagen: </label><input type="file" name="pic"/></th>
    <td><input type="submit" name="primero" value="Agregar" /></td>
  </tr>
</table>
</form> 
Y cuando se procesa el form se muestra esto:
Código HTML:
<img src="../<?php echo $image_info; ?>" alt="Nuevo producto" height="230" width="230" />
<div style="background: #999; font-weight: bold; color: #fff"><?php echo $image_info; ?></div> 
Y en este momento, al darle actualizar es que me carga nuevamente una entrada a la base de datos y me vuelve a subir la imagen...