34849-vm/save_provincia.php
2026-02-03 01:43:03 +00:00

29 lines
793 B
PHP

<?php
session_start();
require_once 'db/config.php';
$db = db();
// Handle update
if (isset($_POST['id'], $_POST['nombre'])) {
$id = $_POST['id'];
$nombre = $_POST['nombre'];
$stmt = $db->prepare("UPDATE provincias SET nombre = ? WHERE id = ?");
$stmt->bind_param('si', $nombre, $id);
$stmt->execute();
$_SESSION['success_message'] = "Provincia actualizada.";
}
// Handle new insertion
if (isset($_POST['new_provincia_nombre'])) {
$nombre = $_POST['new_provincia_nombre'];
if (!empty($nombre)) {
$stmt = $db->prepare("INSERT INTO provincias (nombre) VALUES (?)");
$stmt->bind_param('s', $nombre);
$stmt->execute();
$_SESSION['success_message'] = "Provincia agregada.";
}
}
header("Location: info_producto.php");
exit();
?>