Inserccion datos equipos a BD

parent 81bb332f
......@@ -7,7 +7,7 @@
try {
$conexion=new PDO("mysql:host=$host;dbname=$bd",$usuario,$contrasenia);
if($conexion){echo "Conectado al sistema";}
} catch ( Exception $ex) {
echo $ex->getMessage();
......
<?php include("../template/cabecera.php");?>
<?php
print_r($_POST);
$txtequipo=(isset($_POST['id_equipo']))?$_POST['id_equipo']:"";
$txtnombreEquipo=(isset($_POST['nombreEquipo']))?$_POST['nombreEquipo']:"";
$txtimagen=(isset($_FILES['imgEquipo']['name']))?$_FILES['imgEquipo']['name']:"";
......@@ -14,7 +13,9 @@
switch($accion){
case "Agregar":
//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();
......@@ -23,9 +24,26 @@
break;
case "Cancelar":
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 @@
<div class = "form-group">
<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 class = "form-group">
<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 class = "form-group">
<label for="imgEquipo">Escudo: </label>
<input type="file" class="form-control" name="imgEquipo" id="imgEquipo" placeholder="Añade un escudo">
<label for="imgEquipo">Escudo: <?php echo $txtimagen; ?></label>
<input type="file" class="form-control" name="imgEquipo" id="imgEquipo" placeholder="Añade un escudo">
</div>
<div class="btn-group" role="group" aria-label="">
......@@ -70,21 +88,32 @@
<table class="table table-bordered">
<thead>
<tr>
<th>ID Equipo</th>
<th>Equipo</th>
<th>Jugador</th>
<th>Escudo</th>
<th>Tarjetas</th>
<th>Goles</th>
<th>Acciones</th>
</tr>
</thead>
<tbody>
<?php foreach($listaEquipos as $equipo) {?>
<tr>
<td>Nombre equipo</td>
<td>Nombre jugador</td>
<td><?php echo $equipo['id'] ?></td>
<td><?php echo $equipo['Nombre'] ?></td>
<td><?php echo $equipo['Imagen'] ?></td>
<td>Goles</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>
<?php }?>
</tbody>
</table>
</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