-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheliminar_pokemon.php
63 lines (54 loc) · 2.08 KB
/
eliminar_pokemon.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
include('./utils/config.php');
// Verifica si se ha enviado un formulario para eliminar un Pokémon
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["pokemon_id"])) {
// Obtén el ID del Pokémon a eliminar
$pokemon_id = $_POST["pokemon_id"];
// Crea una conexión a la base de datos
$conn = new mysqli($servername, $username, $password, $database);
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pokémon eliminado</title>
<link rel="icon" href="./assets/pokedex.png" type="image/png">
<!-- Agrega enlaces a las hojas de estilo Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-4">
<?php
// Verifica la conexión
if ($conn->connect_error) {
die("La conexión a MySQL ha fallado: " . $conn->connect_error);
}
// Consulta SQL para eliminar el Pokémon por su ID
$sql = "DELETE FROM favoritos WHERE id = $pokemon_id";
if ($conn->query($sql) === TRUE) {
?>
<div class="alert alert-success text-center" role="alert">
<h1 class="display-4">El Pokémon ha sido eliminado</h1>
</div>
<div class="text-center"> <!-- Agrega la clase text-center aquí para centrar el botón -->
<a class="btn btn-primary" href="favoritos.php">Regresar</a>
</div>
<?php
} else {
?>
<div class="alert alert-danger text-center" role="alert">
<h1 class="display-4">Hubo un error al eliminar el Pokémon con </h1>
</div>
<div class="text-center"> <!-- Agrega la clase text-center aquí para centrar el botón -->
<a class="btn btn-primary" href="favoritos.php">Regresar</a>
</div>
<?php
}
// Cierra la conexión a la base de datos
$conn->close();
}
?>
</div>
</body>
</html>