35888-vm/add_installation.php
2025-11-20 22:00:34 +00:00

39 lines
1.5 KiB
PHP

<?php
session_start();
require_once __DIR__ . '/db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$client_name = trim($_POST['client_name'] ?? '');
$address = trim($_POST['address'] ?? '');
$technician_name = trim($_POST['technician_name'] ?? '');
$observations = trim($_POST['observations'] ?? '');
$voltage = trim($_POST['voltage'] ?? null);
$phase_neutral_ground = trim($_POST['phase_neutral_ground'] ?? null);
$breaker_output = trim($_POST['breaker_output'] ?? null);
if (empty($client_name) || empty($address) || empty($technician_name)) {
$_SESSION['message'] = 'Please fill all required fields.';
$_SESSION['message_type'] = 'danger';
header('Location: index.php');
exit;
}
try {
$pdo = db();
$stmt = $pdo->prepare(
"INSERT INTO installations (client_name, address, technician_name, observations, voltage, phase_neutral_ground, breaker_output) VALUES (?, ?, ?, ?, ?, ?, ?)"
);
$stmt->execute([$client_name, $address, $technician_name, $observations, $voltage, $phase_neutral_ground, $breaker_output]);
$_SESSION['message'] = 'Installation registered successfully!';
$_SESSION['message_type'] = 'success';
} catch (PDOException $e) {
error_log("Database error: " . $e->getMessage());
$_SESSION['message'] = 'Failed to register installation. Please try again.';
$_SESSION['message_type'] = 'danger';
}
}
header('Location: index.php');
exit;