Añadiendo equipos a BD

parent fbad555c
...@@ -15,14 +15,51 @@ ...@@ -15,14 +15,51 @@
//INSERT INTO `equipos` (`id`, `Nombre`, `Imagen`) VALUES (NULL, 'atlethic', 'atlethic.png'); //INSERT INTO `equipos` (`id`, `Nombre`, `Imagen`) VALUES (NULL, 'atlethic', 'atlethic.png');
$SQL=$conexion->prepare("INSERT INTO equipos ( Nombre, Imagen) VALUES (:nombre, :escudo);"); $SQL=$conexion->prepare("INSERT INTO equipos ( Nombre, Imagen) VALUES (:nombre, :escudo);");
$SQL->bindParam(':nombre',$txtnombreEquipo); $SQL->bindParam(':nombre',$txtnombreEquipo);
$SQL->bindParam(':escudo',$txtimagen); $fecha= new DateTime();
$nombreArchivo=($txtimagen!="")?$fecha->getTimestamp()."_".$_FILES["imgEquipo"]["name"]:"imagen.jpg";
$imgtmp=$_FILES["imgEquipo"]["tmp_name"];
if($imgtmp!=""){
move_uploaded_file($imgtmp, "../../img/.$nombreArchivo");
}
$SQL->bindParam(':escudo',$nombreArchivo);
$SQL->execute(); $SQL->execute();
break; break;
case "Modificar": case "Modificar":
$SQL=$conexion->prepare("UPDATE equipos SET nombre=:nombre WHERE id=:id");
$SQL->bindParam(':id',$txtequipo);
$SQL->bindParam(':nombre',$txtnombreEquipo);
$SQL->execute();
if($txtimagen!=""){
$fecha= new DateTime();
$nombreArchivo=($txtimagen!="")?$fecha->getTimestamp()."_".$_FILES["imgEquipo"]["name"]:"imagen.jpg";
$imgtmp=$_FILES["imgEquipo"]["tmp_name"];
move_uploaded_file($imgtmp, "../../img/.$nombreArchivo");
$SQL=$conexion->prepare("SELECT Imagen FROM equipos WHERE id=:id");
$SQL->bindParam(':id',$txtequipo);
$SQL->execute();
$IMGEquipo=$SQL->fetch(PDO::FETCH_LAZY);
if(isset($IMGEquipo["Imagen"]) && ($IMGEquipo["Imagen"]!="imagen.jpg")){
if(file_exists("../../img/".$IMGEquipo["Imagen"])){
unlink("../../img/".$IMGEquipo["Imagen"]);
}
}
$SQL=$conexion->prepare("UPDATE equipos SET Imagen=:imagen WHERE id=:id");
$SQL->bindParam(':id',$txtequipo);
$SQL->bindParam(':imagen',$nombreArchivo);
$SQL->execute();
}
break; break;
case "Cancelar": case "Cancelar":
header("Location:equipos.php");
break; break;
case "Seleccionar": case "Seleccionar":
$SQL=$conexion->prepare("SELECT * FROM equipos WHERE id=:id"); $SQL=$conexion->prepare("SELECT * FROM equipos WHERE id=:id");
...@@ -33,6 +70,16 @@ ...@@ -33,6 +70,16 @@
$txtimagen=$Equipo['Imagen']; $txtimagen=$Equipo['Imagen'];
break; break;
case "Borrar": case "Borrar":
$SQL=$conexion->prepare("SELECT Imagen FROM equipos WHERE id=:id");
$SQL->bindParam(':id',$txtequipo);
$SQL->execute();
$IMGEquipo=$SQL->fetch(PDO::FETCH_LAZY);
if(isset($IMGEquipo["Imagen"]) && ($IMGEquipo["Imagen"]!="imagen.jpg")){
if(file_exists("../../img/".$IMGEquipo["Imagen"])){
unlink("../../img/".$IMGEquipo["Imagen"]);
}
}
$SQL=$conexion->prepare("DELETE FROM equipos WHERE id=:id"); $SQL=$conexion->prepare("DELETE FROM equipos WHERE id=:id");
$SQL->bindParam(':id',$txtequipo); $SQL->bindParam(':id',$txtequipo);
$SQL->execute(); $SQL->execute();
...@@ -58,23 +105,28 @@ ...@@ -58,23 +105,28 @@
<div class = "form-group"> <div class = "form-group">
<label for="id_equipo">ID Equipo: </label> <label for="id_equipo">ID Equipo: </label>
<input type="text" class="form-control" value="<?php echo $txtequipo;?>" name="id_equipo" id="id_equipo" placeholder="Indica el id del nuevo equipo"> <input type="text" required readonly class="form-control" value="<?php echo $txtequipo;?>" name="id_equipo" id="id_equipo" placeholder="Indica el id del nuevo equipo">
</div> </div>
<div class = "form-group"> <div class = "form-group">
<label for="nombreEquipo">Nombre: </label> <label for="nombreEquipo">Nombre: </label>
<input type="text" class="form-control" value="<?php echo $txtnombreEquipo; ?>" name="nombreEquipo" id="nombreEquipo" placeholder="Añade un equipo"> <input type="text" required class="form-control" value="<?php echo $txtnombreEquipo; ?>" name="nombreEquipo" id="nombreEquipo" placeholder="Añade un equipo">
</div> </div>
<div class = "form-group"> <div class = "form-group">
<label for="imgEquipo">Escudo: <?php echo $txtimagen; ?></label> <label for="imgEquipo">Escudo:
<?php echo $txtimagen; ?>
<?php if($txtimagen!=""){ ?>
<img src="../../img/.<?php echo $txtimagen; ?>" width="200" alt="" srcset="">
<?php } ?>
</label>
<input type="file" class="form-control" name="imgEquipo" id="imgEquipo" placeholder="Añade un escudo"> <input type="file" class="form-control" name="imgEquipo" id="imgEquipo" placeholder="Añade un escudo">
</div> </div>
<div class="btn-group" role="group" aria-label=""> <div class="btn-group" role="group" aria-label="">
<button type="submit" name="accion" value="Agregar" class="btn btn-success">Añadir</button> <button type="submit" name="accion" <?php echo ($accion=="Seleccionar")?"disabled":"";?> value="Agregar" class="btn btn-success">Añadir</button>
<button type="submit" name="accion" value="Modificar" class="btn btn-warning">Modificar</button> <button type="submit" name="accion" <?php echo ($accion!="Seleccionar")?"disabled":"";?> value="Modificar" class="btn btn-warning">Modificar</button>
<button type="submit" name="accion" value="Cancelar" class="btn btn-info">Cancelar</button> <button type="submit" name="accion" <?php echo ($accion!="Seleccionar")?"disabled":"";?> value="Cancelar" class="btn btn-info">Cancelar</button>
</div> </div>
</form> </form>
...@@ -101,7 +153,9 @@ ...@@ -101,7 +153,9 @@
<tr> <tr>
<td><?php echo $equipo['id'] ?></td> <td><?php echo $equipo['id'] ?></td>
<td><?php echo $equipo['Nombre'] ?></td> <td><?php echo $equipo['Nombre'] ?></td>
<td><?php echo $equipo['Imagen'] ?></td> <td>
<img src="../../img/.<?php echo $equipo['Imagen']; ?>" width="200" alt="" srcset="">
</td>
<td>Goles</td> <td>Goles</td>
<td>Tarjetas</td> <td>Tarjetas</td>
<td> <td>
......

120 KB | W: | H:

120 KB | W: | H:

img/Athletic.png
img/.1647946660_Athletic.png
img/Athletic.png
img/.1647946660_Athletic.png
  • 2-up
  • Swipe
  • Onion skin

578 KB | W: | H:

578 KB | W: | H:

img/atletico.png
img/.1647946673_atletico.png
img/atletico.png
img/.1647946673_atletico.png
  • 2-up
  • Swipe
  • Onion skin

44.6 KB | W: | H:

44.6 KB | W: | H:

img/Barsa.png
img/.1647946681_Barsa.png
img/Barsa.png
img/.1647946681_Barsa.png
  • 2-up
  • Swipe
  • Onion skin

81.7 KB | W: | H:

81.7 KB | W: | H:

img/betis.png
img/.1647946748_betis.png
img/betis.png
img/.1647946748_betis.png
  • 2-up
  • Swipe
  • Onion skin

27.1 KB | W: | H:

27.1 KB | W: | H:

img/cadiz.png
img/.1647946760_cadiz.png
img/cadiz.png
img/.1647946760_cadiz.png
  • 2-up
  • Swipe
  • Onion skin

38.6 KB | W: | H:

38.6 KB | W: | H:

img/Celta.png
img/.1647946769_Celta.png
img/Celta.png
img/.1647946769_Celta.png
  • 2-up
  • Swipe
  • Onion skin

84.2 KB | W: | H:

84.2 KB | W: | H:

img/Elche.png
img/.1647946777_Elche.png
img/Elche.png
img/.1647946777_Elche.png
  • 2-up
  • Swipe
  • Onion skin

295 KB | W: | H:

295 KB | W: | H:

img/espanyol.png
img/.1647946787_espanyol.png
img/espanyol.png
img/.1647946787_espanyol.png
  • 2-up
  • Swipe
  • Onion skin

50.1 KB | W: | H:

50.1 KB | W: | H:

img/getafe.png
img/.1647946794_getafe.png
img/getafe.png
img/.1647946794_getafe.png
  • 2-up
  • Swipe
  • Onion skin

12.9 KB | W: | H:

12.9 KB | W: | H:

img/Granada.png
img/.1647946802_Granada.png
img/Granada.png
img/.1647946802_Granada.png
  • 2-up
  • Swipe
  • Onion skin

574 KB | W: | H:

574 KB | W: | H:

img/Levante.png
img/.1647946809_Levante.png
img/Levante.png
img/.1647946809_Levante.png
  • 2-up
  • Swipe
  • Onion skin

19.8 KB | W: | H:

19.8 KB | W: | H:

img/Mallorca.png
img/.1647946856_Mallorca.png
img/Mallorca.png
img/.1647946856_Mallorca.png
  • 2-up
  • Swipe
  • Onion skin

94.3 KB | W: | H:

94.3 KB | W: | H:

img/Osasuna.png
img/.1647946864_Osasuna.png
img/Osasuna.png
img/.1647946864_Osasuna.png
  • 2-up
  • Swipe
  • Onion skin

104 KB | W: | H:

104 KB | W: | H:

img/rayo.png
img/.1647946881_rayo.png
img/rayo.png
img/.1647946881_rayo.png
  • 2-up
  • Swipe
  • Onion skin

47.7 KB | W: | H:

47.7 KB | W: | H:

img/madrid.png
img/.1647946901_madrid.png
img/madrid.png
img/.1647946901_madrid.png
  • 2-up
  • Swipe
  • Onion skin

42.4 KB | W: | H:

42.4 KB | W: | H:

img/Sociedad.png
img/.1647946924_Sociedad.png
img/Sociedad.png
img/.1647946924_Sociedad.png
  • 2-up
  • Swipe
  • Onion skin

17.8 KB | W: | H:

17.8 KB | W: | H:

img/Valencia.png
img/.1647946941_Valencia.png
img/Valencia.png
img/.1647946941_Valencia.png
  • 2-up
  • Swipe
  • Onion skin

48.6 KB | W: | H:

48.6 KB | W: | H:

img/Villareal.png
img/.1647946949_Villareal.png
img/Villareal.png
img/.1647946949_Villareal.png
  • 2-up
  • Swipe
  • Onion skin

1.38 MB | W: | H:

1.38 MB | W: | H:

img/sevilla.png
img/.1647947014_sevilla.png
img/sevilla.png
img/.1647947014_sevilla.png
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment