Está en la página 1de 8

INGENIERIA EN SISTEMAS

DESARROLLO DEL CRUD


Yujra Condori Benjamin William
Facultad de Ingeniería, Universidad Privada Domingo Savio
Programación Web I
Ing. Evelin R. Orellana

La Paz – Bolivia
2024
CODIGO ELIMINAR

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Producto eliminado</title>
<link rel="stylesheet" type="text/css" href="css/tienda.css">
</head>
<body>
<h1>Producto eliminado</h1>
<hr>
<p><a href="productos.php">Catálogo</a> &raquo; Eliminado: </p>
<?php
if (isset($_GET["idProducto"])) {
$idProducto = $_GET["idProducto"];

require_once("formas de pago.php");

$eliminar = mysqli_query($conexion, "DELETE FROM productos WHERE


idProducto = '$idProducto'");

if ($eliminar) {
echo "<h2 class=''>Producto eliminado con éxito</h2>";
} else {
echo "<p>Error al intentar eliminar el producto.</p>";
}
}
?>
</body>
</html>

CODIGO EDITAR

<link rel="stylesheet" href="estilo.css">


<?php
require_once("jj.php");

if(isset($_GET['idProducto'])) {
$idProducto = $_GET['idProducto'];

// Consulta para obtener los datos del producto a editar


$consulta = mysqli_query($conexion, "SELECT nombreProducto, descripcion,
precio, cantidad FROM productos WHERE IdProducto = $idProducto");

if(mysqli_num_rows($consulta) == 1) {
$producto = mysqli_fetch_array($consulta);
} else {
// Producto no encontrado
echo "Producto no encontrado.";
exit;
}
} else {
// No se proporcionó el idProducto
echo "ID de producto no especificado.";
exit;
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Aquí puedes procesar los datos enviados por el formulario de edición
// Por ejemplo, actualizar los datos del producto en la base de datos
// Recuerda validar y sanitizar los datos antes de usarlos en consultas
SQL

// Después de procesar los datos, puedes redirigir a otra página


header("Location: formas de pago.php");
exit;
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Editar Producto</title>
</head>

<body>
<h1>Editar Producto</h1>
<form method="post" action="">
<label for="nombre">Nombre:</label>
<input type="text" id="nombre" name="nombre" value="<?php echo
$producto['nombreProducto']; ?>"><br><br>

<label for="descripcion">Descripción:</label>
<textarea id="descripcion" name="descripcion"><?php echo
$producto['descripcion']; ?></textarea><br><br>

<label for="precio">Precio:</label>
<input type="text" id="precio" name="precio" value="<?php echo
$producto['precio']; ?>"><br><br>
<label for="cantidad">Cantidad:</label>
<input type="text" id="cantidad" name="cantidad" value="<?php echo
$producto['cantidad']; ?>"><br><br>

<input type="submit" value="Guardar cambios">


</form>
</body>

</html>

CODIGO DEL FORMULARIO

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tienda en línea</title>
<link rel="stylesheet" href="jj.php">
<link rel="stylesheet" href="tienda.css">
<script>
function confirmacion() {
if (confirm("¿Deseas Eliminar el producto?")) {
return true;
}
return false;
}
</script>
</head>

<body>
<h1>TIENDA BENYI</h1>
<hr>
<h2>CATALOGO</h2>
<div class="agregar">
<a href="agregar.php">Agregar</a>
</div>
<table border="1">
<thead>
<tr>
<th>Nombre</th>
<th>Descripción</th>
<th>Precio</th>
<th>Cantidad</th>
<th>Acciones</th>
</tr>
</thead>
<tbody>
<?php
require_once("jj.php");
$consulta = mysqli_query($conexion, "SELECT nombreProducto,
descripcion, precio, cantidad, IdProducto FROM productos");
while ($fila = mysqli_fetch_array($consulta)) {
$precio = number_format($fila["precio"], 2); // Formatea el
precio a dos decimales
printf('
<tr>
<td>%s</td>
<td>%s</td>
<td>$%s</td>
<td>%s</td>
<td>
<a href="editar.php?idProducto=%s"><img
src="imagenes/iconos/editar.png"></a> <!-- Botón de editar -->
<a href="eliminar.php?idProducto=%s" onclick="return
confirmacion()"><img src="imagenes/iconos/eliminar.png"></a>
</td>
</tr>
', $fila["nombreProducto"],
$fila["descripcion"],
$precio,
$fila["cantidad"],
$fila["IdProducto"],
$fila["IdProducto"]);
}
?>
</tbody>
</table>
</body>
<style>
body {
background-image: url(img/portada.jpg);
background-size: cover;
}
</style>
</html>

También podría gustarte