Inserccion datos equipos a BD

parent 81bb332f
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
try { try {
$conexion=new PDO("mysql:host=$host;dbname=$bd",$usuario,$contrasenia); $conexion=new PDO("mysql:host=$host;dbname=$bd",$usuario,$contrasenia);
if($conexion){echo "Conectado al sistema";}
} catch ( Exception $ex) { } catch ( Exception $ex) {
echo $ex->getMessage(); echo $ex->getMessage();
......
<?php include("../template/cabecera.php");?> <?php include("../template/cabecera.php");?>
<?php <?php
print_r($_POST);
$txtequipo=(isset($_POST['id_equipo']))?$_POST['id_equipo']:""; $txtequipo=(isset($_POST['id_equipo']))?$_POST['id_equipo']:"";
$txtnombreEquipo=(isset($_POST['nombreEquipo']))?$_POST['nombreEquipo']:""; $txtnombreEquipo=(isset($_POST['nombreEquipo']))?$_POST['nombreEquipo']:"";
$txtimagen=(isset($_FILES['imgEquipo']['name']))?$_FILES['imgEquipo']['name']:""; $txtimagen=(isset($_FILES['imgEquipo']['name']))?$_FILES['imgEquipo']['name']:"";
...@@ -14,7 +13,9 @@ ...@@ -14,7 +13,9 @@
switch($accion){ switch($accion){
case "Agregar": case "Agregar":
//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` (`id`, `Nombre`, `Imagen`) VALUES (NULL, 'atlethic', 'atlethic.png');"); $SQL=$conexion->prepare("INSERT INTO equipos ( Nombre, Imagen) VALUES (:nombre, :escudo);");
$SQL->bindParam(':nombre',$txtnombreEquipo);
$SQL->bindParam(':escudo',$txtimagen);
$SQL->execute(); $SQL->execute();
...@@ -23,9 +24,26 @@ ...@@ -23,9 +24,26 @@
break; break;
case "Cancelar": case "Cancelar":
break; break;
case "Seleccionar":
$SQL=$conexion->prepare("SELECT * FROM equipos WHERE id=:id");
$SQL->bindParam(':id',$txtequipo);
$SQL->execute();
$Equipo=$SQL->fetch(PDO::FETCH_LAZY);
$txtnombreEquipo=$Equipo['Nombre'];
$txtimagen=$Equipo['Imagen'];
break;
case "Borrar":
$SQL=$conexion->prepare("DELETE FROM equipos WHERE id=:id");
$SQL->bindParam(':id',$txtequipo);
$SQL->execute();
break;
} }
$SQL=$conexion->prepare("SELECT * FROM equipos");
$SQL->execute();
$listaEquipos=$SQL->fetchAll(PDO::FETCH_ASSOC);
?> ?>
...@@ -40,17 +58,17 @@ ...@@ -40,17 +58,17 @@
<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" name="id_equipo" id="id_equipo" placeholder="Indica el id del nuevo equipo"> <input type="text" 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" name="nombreEquipo" id="nombreEquipo" placeholder="Añade un equipo"> <input type="text" 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: </label> <label for="imgEquipo">Escudo: <?php echo $txtimagen; ?></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="">
...@@ -70,21 +88,32 @@ ...@@ -70,21 +88,32 @@
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>
<tr> <tr>
<th>ID Equipo</th>
<th>Equipo</th> <th>Equipo</th>
<th>Jugador</th> <th>Escudo</th>
<th>Tarjetas</th> <th>Tarjetas</th>
<th>Goles</th> <th>Goles</th>
<th>Acciones</th> <th>Acciones</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach($listaEquipos as $equipo) {?>
<tr> <tr>
<td>Nombre equipo</td> <td><?php echo $equipo['id'] ?></td>
<td>Nombre jugador</td> <td><?php echo $equipo['Nombre'] ?></td>
<td><?php echo $equipo['Imagen'] ?></td>
<td>Goles</td> <td>Goles</td>
<td>Tarjetas</td> <td>Tarjetas</td>
<td>Seleccionar | Borrar</td> <td>
<form method="POST">
<input type="hidden" name="id_equipo" id="id_equipo" value="<?php echo $equipo['id'] ?>"/>
<input type="submit" name="accion" value="Seleccionar" class="btn btn-primary"/>
<input type="submit" name="accion" value="Borrar" class="btn btn-danger"/>
</form>
</td>
</tr> </tr>
<?php }?>
</tbody> </tbody>
</table> </table>
</div> </div>
......
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