Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/08/2012, 16:56
Avatar de novamix
novamix
 
Fecha de Ingreso: enero-2007
Ubicación: Getafe, Spain
Mensajes: 50
Antigüedad: 17 años, 3 meses
Puntos: 1
Busqueda Update bd php.

Hola de nuevo, veran tengo un par de dudas en referencia a como hacer una cosa.

mediante un formulario estoy realizando una actualizacion a la bd. pero tengo una imagen incluida. que hago... bueno pues guardo la ruta de la imagen en la bd, pero cuando le doy actualizar en el formulario, si no cargo ninguna imagen se me borra. . hay alguna forma mediante php de decirle que si no hay imagen no actualize?


os dejo el formulario
Código PHP:
<?php 
include_once( dirname(dirname(__FILE__)) . '/classes/check.class.php');
protect("1");
?>
<?php 
include('header.php'); ?>
<?php 
include('conect.php'); ?>
<div class="container-fluid">
  <div class="row-fluid">
    <div class="span2">
    <?php include('sidebarevent.php'); ?>
    </div>
    <div class="span10">
    <?php $idconcierto $_GET["id"];?>
 
  <?php $result mysql_query("SELECT concierto_id, artista, fecha, hora, sala, direccion, localidad, provincia, pais, imagen FROM concierto WHERE concierto_id = $idconcierto"$conexion);
  
  
  if (!
$result) {
    echo 
"No se pudo ejecutar con exito la consulta ($sql) en la BD: " mysql_error();
    exit;
}

if (
mysql_num_rows($result) == 0) {
    echo 
"No se han encontrado NINGUNA información";
    exit;
}

while (
$rsEmp mysql_fetch_assoc($result)) {
 
?>
 
 
 <div class="row-fluid">
  <div class="span12">
    <div class="row-fluid">
      <div class="span6">
      <form action="./edit3.php?id=<?php echo "$idconcierto" ?> " method="post" name="NewEvent" enctype="multipart/form-data">
      <p>
        <input name="username" type="hidden" id="username" value="<?php echo $_SESSION['jigowatt']['username']; ?>" />
      </p>
      <p>
        <label for="artista">Artista</label>
        <input name="artista" type="text" id="artista" value="<?php echo "$rsEmp[artista]"?>" />
        <br />
        <label for="fecha">Fecha</label>
        <input type="text" name="fecha" id="fecha" value="<?php echo "$rsEmp[fecha]"?>"  />
        <br />
        <label for="hora">Hora</label>
        <input type="text" name="hora" id="hora"value="<?php echo "$rsEmp[hora]"?>"  />
        <br />
        <label for="sala">Sala</label>
        <input type="text" name="sala" id="sala"value="<?php echo "$rsEmp[sala]"?>"  />
        <br />
        <label for="direccion">Direccion</label>
        <input type="text" name="direccion" id="direccion"value="<?php echo "$rsEmp[direccion]"?>"  />
        <br />
         <label for="localidad">Localidad</label>
        <input type="text" name="localidad" id="localidad" value="<?php echo "$rsEmp[localidad]"?>" />
        <br />
        
        <label for="provincia">Provincia</label>
        <input type="text" name="provincia" id="provincia" value="<?php echo "$rsEmp[provincia]"?>" />
        <br />
       
        <label for="pais">País</label>
        <input type="text" name="pais" id="pais" value="<?php echo "$rsEmp[pais]"?>" />
        <br>
        <br />
        <img src="../imagenes/<?php echo "$rsEmp[imagen]"?>" width="91" height="136">
<label for="userfile">userfile</label>
    <input type="file" name="userfile" id="userfile">
    <br />
   
      <p>
        <input type="submit" name="enviar" id="enviar" value="Enviar" class="btn btn-primary"/>
        <input type="reset" name="button" id="button" value="Restablecer" class="btn"/>
      </p>
    </form>
  <?  
}

mysql_free_result($result);
?>
 
 
 
</div>
</div>
</div>
</div>
<?php include('footer.php'); ?>

y el php del update.


Código PHP:
<?php 
include_once( dirname(dirname(__FILE__)) . '/classes/check.class.php');
protect("1");
?>
<?php 
include('header.php'); ?>
<?php 
include('conect.php'); ?>
<div class="container-fluid">
  <div class="row-fluid">
    <div class="span2">
    <?php include('sidebarevent.php'); ?>
    </div>
    <div class="span10"> <?php $idconcierto $_GET["id"];?>

 <?php 
if
   (isset(
$_POST['artista'])) {
 
$artista $_POST['artista'];
 
$fecha $_POST['fecha'];
 
$hora $_POST['hora'];
 
$sala $_POST['sala'];
 
$direccion $_POST['direccion'];
 
$localidad $_POST['localidad'];
 
$provincia $_POST['provincia'];
 
$pais $_POST['pais'];


?>
<?php
    
// Declare variables
    // Get the basic file information
    
$userfile $_FILES['userfile']['name'];
    
$file_size $_FILES['userfile']['size'];
    
$file_temp $_FILES['userfile']['tmp_name'];
    
$file_err $_FILES['userfile']['error'];
    
$path '../imagenes/';
   }
    
// Create a new file name
    // This is so if other files on the server have the same name, it will be renamed
    
$randomizer rand(00009999);
    
$file_name $randomizer.$userfile;

// Get the file type
    // Using $_FILES to get the file type is sometimes inaccurate, so we are going
    // to get the extension ourselves from the name of the file
    // This also eliminates having to worry about the MIME type
    
$file_type $userfile;
    
$file_type_length strlen($file_type) - 3;
    
$file_type substr($file_type$file_type_length);

    if(!empty(
$userfile)) {
        echo 
'';

        
// limit the size of the file to 8 MB
        
if($file_size 8388608) {
            echo 
'Imagen demaciado Grande.. El Tamaño Maximo es de 8 Mb<BR />';
            exit();
        }

        
// Set allowed file types
        // Set case of all letters to lower case
        
$file_type strtolower($file_type);
        
$files = array();
        
$files[] = 'jpeg';
        
$files[] = 'jpg';
        
$files[] = 'gif';
        
$files[] = 'png';
        
// Search the array for the allowed file type
        
$key array_search($file_type$files);
        if(
$key) {
            echo 
'<b>Imagen Correcta</b><br />';
        } else {
            echo 
'<b>La imagen no es validad. solo se admiten JPEG, JPG, GIF O PNG</b><br />';
            exit();
        }

// Check for errors and upload the file
 
if(move_uploaded_file($file_temp'../imagenes/' .$file_name.'')) {
            echo 
'<h3>Imagen subida correctamente.</h3>';
        } else {
            echo 
'<h3>ERROR</h3>';
        }
}

    else {
        echo 
'<h3>Ningun Archivo Seleccionado.</h3>';
    }
?>

<?php

$sql 
"UPDATE  `v2`.`concierto` SET  `artista`='$artista', `fecha`= '$fecha', `hora`='$hora', `sala`='$sala', `direccion`='$direccion', `localidad`='$localidad', `provincia`='$provincia', `pais`='$pais',`imagen`='$file_name' WHERE  `concierto`.`concierto_id` =$idconcierto;";

mysql_query($sql,$conexion);

$my_error mysql_error($conexion);

if(!empty(
$my_error)) { 

echo 
"Ha habido un error al EDITAR El concierto. $my_error"

} else{
echo 
"<div class='alert alert-success'> <button type='button' class='close' data-dismiss='alert'>×</button>Concierto EDITADO Correctamente, <a href='../concierto.php?id=$idconcierto' class='btn btn-mini btn-primary'>Puede verlo desde  Aqui.</a></div></br>";
}

?>
 
</div>
</div>
</div>
</div>
<?php include('footer.php'); ?>

un saludo y gracias