Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/05/2008, 04:57
pcmac
 
Fecha de Ingreso: febrero-2004
Mensajes: 47
Antigüedad: 21 años
Puntos: 0
Ayuda con actualizar un Registro

Hola a todo/as:
queria comentarles el siguiente problemita que tengo. Hay muchas cosas que he pedido ayuda aqui y siempre me han ayudado, pero este problema no se si tenga solucion. Estoy desesperada y no se como resolver el asunto.
Tengo un formulario que es para subir y/o actualizar 3 imagenes cuyos nombres se guardan en una BD y el fichero en una carpeta llamada Archivos.
Me funciona perfectamente que lea los nombres de las imagenes que ya se hayan subido y me los muestra, tambien y que si alguna de las imagenes se quiera borrar, pues se borran tanto de la BD como de la carpeta donde se guardan.

El mayor problema es cuando quiero añadir una imagen y ya existia otra en la BD.
lo que me hace es que me añade la nueva pero me borra de la BD el nombre de las imagenes que ya habia, o sea, me pone en blanco el nombre que existiia de otras imagenes subidas anteriormente, me explico? esto ocurre al hacer click en el boton ACTUALIZAR DATOS.

Aqui pongo el codigo fuente de la pagina:

Código PHP:

<?php require_once('Connections/miconexion.php');?>

<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$nombre1 strtr($_FILES['foto1']['name'], "ñ'ÁÉÍÓÚÀÈÌÒÙáéíóúäëïöüàèìòù ""n-AEIOUAEIOUaeiouaeiouaeiou_"); 
if (
$nombre1 <>''){
$nuevoNombre1 time().$HTTP_POST_FILES['foto1']['name'];
copy($_FILES['foto1']['tmp_name'],"archivos/$nuevoNombre1"); 
} else {
if (
$nombre1 ==$row_Recordset1['foto1']){
$nuevoNombre1 =$row_Recordset1['foto1'];
} else {
$nuevoNombre1 ='';
}
}


$nombre2 strtr($_FILES['foto2']['name'], "ñ'ÁÉÍÓÚÀÈÌÒÙáéíóúäëïöüàèìòù ""n-AEIOUAEIOUaeiouaeiouaeiou_"); 
if (
$nombre2 <>''){
$nuevoNombre2 time().$HTTP_POST_FILES['foto2']['name'];
copy($_FILES['foto2']['tmp_name'],"archivos/$nuevoNombre2"); 

} else {
if (
$nombre2 ==$row_Recordset1['foto2']){
$nuevoNombre2 =$row_Recordset1['foto2'];
} else {
$nuevoNombre2 ='';
}
}


$nombre3 strtr($_FILES['foto3']['name'], "ñ'ÁÉÍÓÚÀÈÌÒÙáéíóúäëïöüàèìòù ""n-AEIOUAEIOUaeiouaeiouaeiou_"); 
if (
$nombre3 <>''){
$nuevoNombre3 time().$HTTP_POST_FILES['foto3']['name'];
copy($_FILES['foto3']['tmp_name'],"archivos/$nuevoNombre3"); 

} else {
if (
$nombre3 ==$row_Recordset1['foto3']){
$nuevoNombre3 =$row_Recordset1['foto3'];
} else {
$nuevoNombre3 ='';
}
}


$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

$colname_Recordset1 "-1";
if (isset(
$_GET['id'])) {
  
$colname_Recordset1 $_GET['id'];
}
mysql_select_db($database_miconexion$miconexion);
$query_Recordset1 sprintf("SELECT * FROM promo WHERE id = %s"GetSQLValueString($colname_Recordset1"int"));
$Recordset1 mysql_query($query_Recordset1$miconexion) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);


if ((isset(
$_POST["MM_update"])) && ($_POST["MM_update"] == "formulario")) {


if (
$nombre1 <>''){
$nuevoNombre1 time().$HTTP_POST_FILES['foto1']['name'];
copy($_FILES['foto1']['tmp_name'],"archivos/$nuevoNombre1"); 
} else {
if (
$nombre1 ==$row_Recordset1['foto1']){
$nuevoNombre1 =$row_Recordset1['foto1'];
} else {
$nuevoNombre1 ='';
}
}


if (
$nombre2 <>''){
$nuevoNombre2 time().$HTTP_POST_FILES['foto2']['name'];
copy($_FILES['foto2']['tmp_name'],"archivos/$nuevoNombre2"); 

} else {
if (
$nombre2 ==$row_Recordset1['foto2']){
$nuevoNombre2 =$row_Recordset1['foto2'];
} else {
$nuevoNombre2 ='';
}
}


if (
$nombre3 <>''){
$nuevoNombre3 time().$HTTP_POST_FILES['foto3']['name'];
copy($_FILES['foto3']['tmp_name'],"archivos/$nuevoNombre3"); 

} else {
if (
$nombre3 ==$row_Recordset1['foto3']){
$nuevoNombre3 =$row_Recordset1['foto3'];
} else {
$nuevoNombre3 ='';
}
}


$updateSQL "UPDATE promo SET foto1='$nuevoNombre1', foto2='$nuevoNombre2', foto3='$nuevoNombre3' WHERE id='$colname_Recordset1'"

  
mysql_select_db($database_miconexion$miconexion);
  
$Result1 mysql_query($updateSQL$miconexion) or die(mysql_error());

  
$updateGoTo "actualizado.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$updateGoTo .= (strpos($updateGoTo'?')) ? "&" "?";
    
$updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$updateGoTo));
}
?>

Codigo del formulario:

Código HTML:
<form action="<?php echo $editFormAction; ?>" method='POST' enctype="multipart/form-data" name='formulario' id='formulario'><br />
          Datos de las imagenes:<br /><br />
      <center>
  <table width="591" border="0">
  <tr class="Estilo2">
    <td width="193">Insertar Im&aacute;genes</td>
    <td width="388" class="Estilo2">&nbsp;</td>
    </tr>
  <tr class="Estilo2">
    <td valign="bottom">&nbsp;</td>
    <td><?php if ($row_Recordset1['foto1'] <>''){?>
      <a href="archivos/<?php echo $row_Recordset1['foto1']; ?>" target="_blank"> <img src="archivos/<?php echo $row_Recordset1['foto1']; ?>" border="0" width="100" height="100" /></a>
      
      <br />Para cambiar la foto, primero debe <br />
      eliminarla haciendo click  
      <a href="borrar_imagen.php?Fichero=<?php echo $row_Recordset1['foto1'];?>">aqu&iacute;</a>
      <?php 
	  
	  } else { ?>
      <input name="foto1" type="file" id="foto1" value="<?php echo $row_Recordset1['foto1']; ?>" />
      <?php } ?></td>
    </tr>
  <tr class="Estilo2">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
  <tr class="Estilo2">
    <td>&nbsp;</td>
    <td><?php if ($row_Recordset1['foto2'] <>''){?>
      <a href="archivos/<?php echo $row_Recordset1['foto2']; ?>" target="_blank"> <img src="archivos/<?php echo $row_Recordset1['foto2']; ?>" border="0" width="100" height="100" /></a>
      <br />Para cambiar la foto, primero debe <br />
      eliminarla haciendo click 
      <a href="borrar_imagen.php?Fichero=<?php echo $row_Recordset1['foto2']; ?>">aqu&iacute;</a>
	  <?php 
	  
	  } else { ?>
      <input name="foto2" type="file" id="foto2" value="<?php echo $row_Recordset1['foto2']; ?>" />
            
      <?php } ?></td>
    </tr>
  <tr class="Estilo2">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
  <tr class="Estilo2">
    <td>&nbsp;</td>
    <td><?php if ($row_Recordset1['foto3'] <>''){?>
      <a href="archivos/<?php echo $row_Recordset1['foto3']; ?>" target="_blank"> <img src="archivos/<?php echo $row_Recordset1['foto3']; ?>" border="0" width="100" height="100" /></a>
      <br />Para cambiar la foto, primero debe <br />
      eliminarla haciendo click 
      <a href="borrar_imagen.php?Fichero=<?php echo $row_Recordset1['foto3']; ?>">aqu&iacute;</a>
      <?php 
	  
	  } else { ?>
      <input name="foto3" type="file" id="foto3" value="<?php echo $row_Recordset1['foto3']; ?>" />

      <?php } ?></td>
    </tr>
  <tr class="Estilo2">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td><span class="Estilo2">
    <?php if (!$row_Recordset1['foto1'] ='' AND !$row_Recordset1['foto2'] ='' AND !$row_Recordset1['foto3'] =''){ ?>
      <input type='submit' value='Actualizar datos' />
      <?php } ?>
    </span></td>
    </tr>
</table>
</center>
    <br />
      <input type="hidden" name="MM_update" value="formulario" />
    </form> 
Ah! por si alguien pregunta, trabajo con Dreamweaver CS3 y mucho de los codigos que muestro, los genera automaticamente el Dreamweaver.

Muchas gracias a todos. Espero vuestra amable ayuda.

PCMAC