Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/02/2008, 05:50
Licrat
 
Fecha de Ingreso: enero-2008
Mensajes: 58
Antigüedad: 16 años, 3 meses
Puntos: 1
[Urgente!] solo borra ultimo registro y borrar en carpeta

tengo este codigo :

Código:
<?
$servidor = "localhost";
$usuario = "";
$contrasenia = "";

$cnx = mysql_connect($servidor,$usuario,$contrasenia) or die(mysql_error());

mysql_select_db("guiamusica_bd",$cnx) or die (mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<style type="text/css">
<!--
body {
	background-color: #FFFFFF;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	margin-left: 50px;
}
body,td,th {
	color: #000000;
}
.letra {
	font-family: HandelGotDLig;
	font-size: 12px;
	color: #000000;
	margin-left: 350px;
}
.cwe1 {
	font-family: HandelGotDLig;
	font-size: 12px;
	color: #FFFFFF;
	background-image: url(../imagenes/fondo%20botones.jpg);
	background-repeat: no-repeat;
	background-position: center center;
	font-weight: bold;
	width: 100px;
}
.cwe {
	font-family: HandelGotDLig;
	font-size: 12px;
	color: #000000;
	background-color: #FFFFFF;
	border: 1px outset #000000;
	vertical-align: middle;
}
.transparente {
	background-color: transparent;
	font-family: HandelGotDLig;
	font-size: 12px;
	color: #000000;
	width: 500px;
	border-top-width: 0px;
	border-right-width: 0px;
	border-bottom-width: 0px;
	border-left-width: 0px;
}
-->
</style>
</head>
<body>
<form method="post" name="form3" id="form3" enctype="multipart/form-data" target="frame1">
  <table width="750" border="0">
    <tr class="cwe">
      <td><div align="center">
        <input name="foto" type="file" class="cwe" id="fichero" />
        <input name="Submit" type="submit" class="cwe1" value="A&ntilde;adir foto" />
      </div></td>
              <?
	if(isset($_POST["Submit"]))
	{
	
	$imagen = $_FILES["foto"]["name"];
	$imagenTmp = $_FILES["foto"]["tmp_name"];
	
	if(copy($imagenTmp,"fotos/".$_GET["grupo"]."/".$imagen))
	{
		echo "<br />Archivo subido";
	}
	else
	{
		echo "<br />Error";
	}
		
	$foto = $_FILES["foto"]["name"];
	$grupo = $_GET["grupo"];
	 
	$c = "INSERT INTO fotos (id_foto,foto,grupo) VALUES ('','$foto','$grupo')";
	$q = mysql_query($c) or die (mysql_error());
	?>
      <script>
	window.open('marco edicion artistas fotos artista.php?grupo=<? echo $_GET["grupo"]; ?>','frame1');
	  </script>
    <?
	}
	?>
    </tr>
  </table>
</form>
<table width="750" border="0">
           <?
		$grupo = $_GET["grupo"];
		$consulta = "SELECT * FROM fotos WHERE grupo='$grupo'";
		$query = mysql_query($consulta) or die (mysql_error());
		
		$filas = mysql_num_rows($query);
		
		if($filas>0)
		{
		while($res = mysql_fetch_array($query))
		{
		?>
   <form action="" method="post" name="registro<? echo $res["foto"]; ?>">
    <tr class="cwe">
      <td width="33" height="34" class="cwe"><a href="fotos/<? echo $_GET["grupo"]; ?>/<? echo $res["foto"]; ?>"><img src="fotos/<? echo $_GET["grupo"]; ?>/<? echo $res["foto"]; ?>" width='30' height='30' border="0"/></a></td>
      <td width="585" class="cwe"><div align="center">
        <? echo $res["foto"]; ?>
      </div></td>
      <td width="82" class="cwe"><span class="cwe">
      <a href="marco edicion editar foto.php?foto=<? echo $res["foto"]; ?>&&grupo=<? echo $_GET["grupo"]; ?>">
        <input name="editar" type="button" class="cwe1" value="Editar"/></a>
      </span></td>
      <td width="82" class="cwe">
        <input name="eliminar" type="button" class="cwe1" onclick="MM_callJS('eliminar()')" value="Eliminar"/>
     <script language="Javascript">
	function eliminar() {
       ventana=confirm("Seguro que quieres Eliminarlo");
       if (ventana) {
		window.open('borrar_foto.php?foto=<? echo $res["foto"]; ?>&&grupo=<? echo $_GET["grupo"]; ?>','frame1');
       }
       else {
		window.open('marco edicion artistas fotos artista.php?grupo=<? echo $_GET["grupo"]; ?>','frame1');
       }   
	}        
	function MM_callJS(jsStr) 
	{ //v2.0
	  return eval(jsStr)
	}                   
	</script>
      </td>
    </tr>
    </form>
	<?
	}
	} 
	else 
	{
	echo "<div class='letra'>no hay fotos</div>";
	}
   ?>
  </table>  	
</body>
</html>
<?
mysql_close($cnx);
?>
el boton "eliminar" justo con su programacion llevan a esta programacion (en otra pagina) :

Código:
<?
	$servidor = "localhost";
	$usuario = "";
	$contrasenia = "";
	
	$cnx = mysql_connect($servidor,$usuario,$contrasenia) or die(mysql_error());
	
	mysql_select_db("guiamusica_bd",$cnx) or die (mysql_error());

   	$foto = $_GET["foto"];
	
	$consulta = "DELETE FROM fotos WHERE foto='$foto'";
	$query = mysql_query($consulta) or die (mysql_error());
	?>
     <script>
	window.open('marco edicion artistas fotos artista.php?grupo=<? echo $_GET["grupo"]; ?>','frame1');
	 </script>
    <?
	mysql_close($cnx);
?>
tengo dos problemas:

- el primer problema, esque al eliminar un archivo, solo elimina el ultimo que se ha insertado.

-el segundo esque quisiera saber como hacer que al mismo tiempo que se borra un archivo de la base de datos que se borre el archivo de una carpeta.

Un saludo y gracias por adelantado