Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/03/2012, 16:19
yole
 
Fecha de Ingreso: julio-2007
Mensajes: 287
Antigüedad: 16 años, 9 meses
Puntos: 4
Pregunta Borrar registros con checkbox

Como están Maestros, mi problema es el siguiente:

Trato de borrar múltiples registros de una tabla utilizando Checkbox.

Tengo fotos guardadas en carpetas y las rutas en una tabla.
Cuando hago la selección de las fotos que voy a borra y presiono el botón borrar estas se borran sin problema pero las rutas guardadas en las tablas no se borran.

Dejaré acá el script por si alguien me da una mano y también por si a otro le sirve (una ves corregido) claro está.

Código PHP:
Ver original
  1. //pagina que contiene los checkbox
  2. Marque para borrar
  3. <input type='checkbox' name='idfotog[]' value='".$row['idfotog']."'>
  4. <input type='text' size='1' value='".$row['idfotog']."' />
  5. <input type="submit" name="button" id="button" value="Borrar las fotos seleccionadas" />

Código PHP:
Ver original
  1. //y la pagina que procesa
  2.  
  3.  
  4. $idfotos=$_POST['idfotog'];
  5.  
  6. $contador=0;
  7.  
  8. if(is_array($idfotos))
  9.     {
  10.         for($i=0;$i<count($idfotos);$i++){
  11.        
  12.         //hago la consulta para obtener los nombres de las fotos
  13.         $sql="select * from fotosGaleria where idfotog = '".$idfotos[$i]."'";
  14.         $res=mysql_query($sql)or die(mysql_error);
  15.         $row=mysql_fetch_array($res);
  16.        
  17.         $rutafoto=$row['rutafoto'];
  18.         $idfotog=$row['idfotog'];
  19.        
  20.                 //borro las fotos de la carpeta
  21.                 $borrar1 = $_SERVER['DOCUMENT_ROOT']."/".$rutafoto;
  22.                 //echo "borrar: ".$borrar1."<br>";
  23.                 unlink($borrar1);
  24.                
  25.         $variablennnn = $idfotos[$i];
  26.         //mysql_query("delete from fotosGaleria where idpro = '".$variablennnn."'");
  27.         $query = "DELETE form fotosGaleria where idfotog ='".$variablennnn."'";
  28.         //$row2=mysql_query("delet form fotosGaleria where idfotog ='".$idfotos[$i]."'");
  29.         //echo $borrar1."<br>";
  30.         //echo $idfotos[$i]."<br>";
  31.         echo $variablennnn;
  32.        
  33.         //echo $idfotos[$i]."-". $rutafoto."<br>";
  34.        
  35.         $contador++;
  36.        
  37.         echo "<script>alert('La foto fue borrada de la base de datos');
  38.                         location.href='index.php';
  39.                     </script>";
  40.        
  41.         }
  42.     }
  43.     else
  44.     {
  45.         echo "<script>history.back(alert('Seleccione las fotos que quiere borrar.'));</script>";
  46.             die();
  47.     }