<form method="POST" action="">
<input type="hidden" name="form_type" value="entrada">
<label for="Id_Producto">ID del Producto:</label>
<input type="text" id="Id_Producto" name="Id_Producto" required><br><br>
<label for="Cantidad">Cantidad:</label>
<input type="number" id="Cantidad" name="Cantidad" required><br><br>
<label for="Peso_Type">Tipo de Peso:</label>
<select name="Peso_Type" id="pesoType" onchange="showWeightInput()">
<option value="unidad">Por Unidad</option>
<option value="lote">Por Lote</option>
</select>
<label for="Peso_Measure">Tipo de Medida:</label>
<select name="Peso_Measure">
<option value="libras">Lbs</option>
<option value="kilos">K</option>
<option value="toneladas">T</option>
</select>
<label for="Peso">Peso:</label>
<input type="text" name="Peso" required>
<br><br>
<label for="Origen">Origen:</label>
<input type="text" name="Origen" required><br><br>
<label for="Descripcion">Descripción:</label>
<input type="text" id="Descripcion" name="Descripcion" required><br><br>
<label for="Precio_unitario">Precio Unitario en Dolar:</label>
<input type="number" id="Precio_unitario" name="Precio_unitario" step="0.01"
required><br><br>
<label for="Categoria">Categoría:</label>
<select id="Categoria" name="Categoria" required>
<option value="Alimentos">Alimentos</option>
<option value="Ropa">Ropa</option>
<option value="Tecnología">Tecnología</option>
<option value="Deporte">Deporte</option>
<option value="Juguetes">Juguetes</option>
<option value="Vehículos y Piezas">Vehículos y Piezas</option>
<option value="Maquinarias y Equipos">Maquinarias y Equipos</option>
<option value="Material de Construcción">Material de Construcción</option>
</select><br><br>
<label for="Fecha_Entrada">Fecha de Entrada:</label>
<input type="date" id="Fecha_Entrada" name="Fecha_Entrada" required><br><br>
<label for="Proveedor">Proveedor:</label>
<input type="text" id="Proveedor" name="Proveedor" required><br><br>
<label for="Estado">Estado:</label>
<select id="Estado" name="Estado" required>
<option value="Bueno">Bueno</option>
<option value="Intermedio">Intermedio</option>
<option value="Malo">Malo</option>
</select><br><br>
<input type="submit" value="Enviar">
</form>
<?php if (!empty($message)): ?>
<div class="message"><?php echo $message; ?></div>
<?php endif; ?>
<style>
.message {
margin-bottom: 15px;
padding: 10px;
background-color: #e0f7fa;
border: 1px solid #00796b;
color: #00796b;
border-radius: 5px;
display: inline-block; /* Esto limita el ancho al contenido */
</style>
</body>
</html>
CODIGO DE GESTION
<?php
$host = "localhost";
$usuario = "root";
$password = "";
$baseDeDatos = "lya";
$conexion = new mysqli($host, $usuario, $password, $baseDeDatos);
if ($conexion->connect_error) {
die("Error de conexión: " . $conexion->connect_error);
if (isset($_GET['eliminar'])) {
$id = $_GET['eliminar'];
$sql = "DELETE FROM productos WHERE Id_Producto='$id'";
$conexion->query($sql);
if (isset($_POST['editar'])) {
$id = $_POST['id'];
$cantidad = $_POST['cantidad'];
$origen = $_POST['origen'];
$peso = $_POST['peso'];
$descripcion = $_POST['descripcion'];
$precio_unitario = $_POST['precio_unitario'];
$categoria = $_POST['categoria'];
$proveedor = $_POST['proveedor'];
$estado = $_POST['estado'];
$sql = "UPDATE entradas SET
Cantidad='$cantidad',
Origen='$origen',
Peso='$peso',
Descripcion='$descripcion',
Precio_unitario='$precio_unitario',
Categoria='$categoria',
Proveedor='$proveedor',
Estado='$estado'
WHERE Id_Producto='$id'";
$conexion->query($sql);
$idProducto = "";
$categoria = "";
$sql = "SELECT * FROM entradas";
if (isset($_POST['buscar'])) {
$idProducto = $_POST['id_producto'];
$categoria = $_POST['categoria'];
if (!empty($idProducto)) {
$sql = "SELECT * FROM entradas WHERE Id_Producto LIKE '%$idProducto%'";
} elseif (!empty($categoria)) {
$sql = "SELECT * FROM entradas WHERE Categoria LIKE '%$categoria%'";
}
$resultado = $conexion->query($sql);
$totalResultados = $resultado->num_rows;
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Gestión de Productos</title>
</head>
<body>
<h1>Gestión de Productos</h1>
<form method="post" action="">
<label for="id_producto">Buscar por ID de Producto:</label>
<input type="text" name="id_producto" value="<?php echo htmlspecialchars($idProducto); ?
>">
<label for="categoria">Buscar por Categoría:</label>
<input type="text" name="categoria" value="<?php echo htmlspecialchars($categoria); ?>">
<input type="submit" name="buscar" value="Buscar">
</form>
<table border="1">
<tr>
<th>ID Producto</th>
<th>Cantidad</th>
<th>Origen</th>
<th>Peso</th>
<th>Descripción</th>
<th>Precio Unitario</th>
<th>Categoría</th>
<th>Proveedor</th>
<th>Estado</th>
<th>Acciones</th>
</tr>
<?php if ($totalResultados > 0): ?>
<?php while($row = $resultado->fetch_assoc()) {
// Color de fondo basado en el estado del producto
$colorEstado = '';
switch ($row['Estado']) {
case 'Bueno':
$colorEstado = 'green';
break;
case 'Intermedio':
$colorEstado = 'yellow';
break;
case 'Malo':
$colorEstado = 'red';
break;
?>
<tr>
<td><?php echo $row['Id_Producto']; ?></td>
<!-- Celda de cantidad con fondo rojo si el valor es menor o igual a 100 -->
<td style="background-color: <?php echo ($row['Cantidad'] <= 100) ? 'red' :
'transparent'; ?>;">
<?php echo $row['Cantidad']; ?>
</td>
<td><?php echo $row['Origen']; ?></td>
<td><?php echo $row['Peso']; ?></td>
<td><?php echo $row['Descripcion']; ?></td>
<td><?php echo $row['Precio_unitario']; ?></td>
<td><?php echo $row['Categoria']; ?></td>
<td><?php echo $row['Proveedor']; ?></td>
<!-- Celda de estado con color de fondo basado en el valor de estado -->
<td style="background-color: <?php echo $colorEstado; ?>;">
<?php echo $row['Estado']; ?>
</td>
<td>
<a href="gestionar_productos.php?eliminar=<?php echo $row['Id_Producto']; ?>"
onclick="return confirm('¿Estás seguro de eliminar este producto?');">Eliminar</a>
| <a href="gestionar_productos.php?editar=<?php echo $row['Id_Producto']; ?
>">Editar</a>
</td>
</tr>
<?php } ?>
<?php else: ?>
<tr>
<td colspan="10">Producto no encontrado</td>
</tr>
<?php endif; ?>
</table>
<?php if (isset($_GET['editar'])): ?>
<?php
$id = $_GET['editar'];
$editarSQL = "SELECT * FROM productos WHERE Id_Producto='$id'";
$resultadoEditar = $conexion->query($editarSQL);
$producto = $resultadoEditar->fetch_assoc();
?>
<h2>Editar Producto</h2>
<form action="gestionar_productos.php" method="post">
<input type="hidden" name="id" value="<?php echo $producto['Id_Producto']; ?>">
<label>Cantidad:</label><br>
<input type="number" name="cantidad" value="<?php echo $producto['Cantidad']; ?
>"><br>
<label>Origen:</label><br>
<input type="text" name="origen" value="<?php echo $producto['Origen']; ?>"><br>
<label>Peso:</label><br>
<input type="text" name="peso" value="<?php echo $producto['Peso']; ?>"><br>
<label>Descripción:</label><br>
<textarea name="descripcion"><?php echo $producto['Descripcion']; ?></textarea><br>
<label>Precio Unitario:</label><br>
<input type="text" name="precio_unitario" value="<?php echo
$producto['Precio_unitario']; ?>"><br>
<label>Categoría:</label><br>
<input type="text" name="categoria" value="<?php echo $producto['Categoria']; ?>"><br>
<label>Proveedor:</label><br>
<input type="text" name="proveedor" value="<?php echo $producto['Proveedor']; ?
>"><br>
<label>Estado:</label><br>
<input type="text" name="estado" value="<?php echo $producto['Estado']; ?>"><br>
<input type="submit" name="editar" value="Guardar Cambios">
</form>
<?php endif; ?>
</body>
</html>