-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprocesar_hotel.php
More file actions
59 lines (49 loc) · 2.1 KB
/
procesar_hotel.php
File metadata and controls
59 lines (49 loc) · 2.1 KB
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
<?php
include 'db.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$nombre = $_POST['nombre'];
$ubicacion = $_POST['ubicacion'];
$habitaciones_disponibles = $_POST['habitaciones_disponibles'];
$tarifa_noche = $_POST['tarifa_noche'];
$database = new Database();
$db = $database->getConnection();
$query = "INSERT INTO HOTEL (nombre, ubicacion, habitaciones_disponibles, tarifa_noche) VALUES (:nombre, :ubicacion, :habitaciones_disponibles, :tarifa_noche)";
$stmt = $db->prepare($query);
$stmt->bindParam(':nombre', $nombre);
$stmt->bindParam(':ubicacion', $ubicacion);
$stmt->bindParam(':habitaciones_disponibles', $habitaciones_disponibles);
$stmt->bindParam(':tarifa_noche', $tarifa_noche);
if ($stmt->execute()) {
// Obtener el id del hotel insertado
$id_hotel = $db->lastInsertId();
// Insertar en la tabla RESERVA
$id_cliente = 1; // Asumiendo un id_cliente fijo para este ejemplo
$fecha_reserva = date('Y-m-d');
$id_vuelo = NULL; // Por ahora no hay vuelo asignado
$query_reserva = "INSERT INTO RESERVA (id_cliente, fecha_reserva, id_vuelo, id_hotel) VALUES (:id_cliente, :fecha_reserva, :id_vuelo, :id_hotel)";
$stmt_reserva = $db->prepare($query_reserva);
$stmt_reserva->bindParam(':id_cliente', $id_cliente);
$stmt_reserva->bindParam(':fecha_reserva', $fecha_reserva);
$stmt_reserva->bindParam(':id_vuelo', $id_vuelo);
$stmt_reserva->bindParam(':id_hotel', $id_hotel);
if ($stmt_reserva->execute()) {
echo "Hotel y reserva agregados correctamente.";
} else {
echo "Error al agregar la reserva.";
}
} else {
echo "Error al agregar el hotel.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Resultado de la Reserva</title>
</head>
<body>
<button onclick="window.location.href='index.html'">Volver a la página principal</button>
</body>
</html>