Preparacion examen

This commit is contained in:
2024-04-03 13:54:49 +02:00
parent 29f5fc3d08
commit 35ee82dcf9
14 changed files with 489 additions and 85 deletions

View File

@@ -0,0 +1,20 @@
<?php
include("connection.php");
$con = connection();
$producto_id = $_GET["producto_id"];
// Borrar en productos
$sql = "DELETE FROM productos WHERE producto_id='$producto_id'";
$query = mysqli_query($con, $sql);
if ($query) {
Header("Location: index_productos.php");
} else {
$mensaje = "Se ha producido un error al borrar el registro.";
$mensaje_codificado = urlencode($mensaje);
header("Location: index_productos.php?mensaje=" . $mensaje_codificado);
exit;
}

View File

@@ -0,0 +1,27 @@
<?php
include("connection.php");
$con = connection();
// Recuperar los datos del formulario
$producto_id = $_POST["producto_id"];
$nombre = $_POST["nombre"];
$precio = $_POST["precio"];
// Actualizo en productos
$sql = "UPDATE productos SET nombre='$nombre', precio='$precio' WHERE producto_id='$producto_id'";
$query = mysqli_query($con, $sql);
if($query){
$mensaje ="Producto actualizado.";
$mensaje_codificado = urlencode($mensaje);
header("Location: index_productos.php?mensaje=".$mensaje_codificado);
exit;
}else{
$mensaje ="Se ha producido un error al actualizar.";
$mensaje_codificado = urlencode($mensaje);
header("Location: index_productos.php?mensaje=".$mensaje_codificado);
exit;
}

View File

@@ -0,0 +1,90 @@
<?php
include("connection.php");
$con = connection();
$sql = "SELECT * FROM productos"; //TODO: Cambiar tabla
$query = mysqli_query($con, $sql);
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/style.css" rel="stylesheet">
<title></title> //TODO: Cambiar titulo
</head>
<body>
<nav> //TODO: Cambiar Navegacion
<ul>
<li><a href="index_clientes.php">Clientes</a></li>
<li class="active"><a href="index_productos.php">Productos</a></li>
<li><a href="index_pedidos.php">Pedidos</a></li>
</ul>
</nav>
<div class="users-table">
<h2></h2>//TODO: Cambiar cabecera tabla titulo
<form action="insert_xxx.php" method="POST"> //TODO: Cambiar archivo para guardar el registro
<table>
<tr>
<td>
<label for="nombre">Nombre:</label>
</td>
<td>
<label for="correo">Precio:</label>
</td>
<td>
</td> <!-- Celda vacía para el botón de envío -->
</tr>
<tr>
<td>
<input type="text" name="nombre" id="nombre" required>
</td>
<td>
<input type="text" name="precio" id="precio" required>
</td>
<td>
<td>
<input type="submit" value="Registrarse">
</td>
</tr>
</table>
</form>
<?php if (isset($_GET['mensaje'])) echo "<p>" . $_GET['mensaje'] . "</p>"; ?>
</div>
<div class="users-table">
<h2>Productos registrados</h2>
<table>
<thead>
<tr>
<th>Producto ID</th>
<th>Nombre</th>
<th>Precio</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php while ($fila = mysqli_fetch_array($query)) { ?>
<tr>
<th><?= $fila['producto_id'] ?></th>
<th><?= $fila['nombre'] ?></th>
<th><?= $fila['precio'] ?></th>
<th><a href="update_producto.php?producto_id=<?php echo $fila['producto_id'] ?>" class="users-table--edit">Editar</a></th>
<th><a href="delete_producto.php?producto_id=<?php echo $fila['producto_id'] ?>" class="users-table--delete">Eliminar</a></th>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</body>
</html>

View File

@@ -0,0 +1,40 @@
<?php
include("connection.php");
$con = connection();
$producto_id = $_GET['producto_id'];
$sql = "SELECT * FROM productos
WHERE producto_id = '$producto_id'";
$query = mysqli_query($con, $sql);
$fila = mysqli_fetch_array($query);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/style.css" rel="stylesheet">
<title>Editar producto</title>
</head>
<body>
<div class="users-form">
<form action="edit_producto.php" method="POST">
<input type="hidden" name="producto_id" id="producto_id" value="<?= $fila['producto_id'] ?>" />
<label for="nombre">Nombre:</label>
<input type="text" name="nombre" id="nombre" value="<?= $fila['nombre'] ?>" required>
<br><br>
<label for="precio">Precio:</label>
<input type="text" name="precio" id="precio" value="<?= $fila['precio'] ?>" required>
<br><br>
<input type="submit" value="Actualizar">
</form>
</div>
</body>
</html>