- Add a database setup script to create the `missions` table. - Implement a modal form for creating new missions. - Add backend PHP logic to handle form submission and save missions to the database. - Display the list of missions dynamically from the database.
34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
<?php
|
|
require_once 'config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
$sql = "
|
|
CREATE TABLE IF NOT EXISTS missions (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(255) NOT NULL,
|
|
drone VARCHAR(255) NOT NULL,
|
|
status VARCHAR(50) NOT NULL,
|
|
mission_date DATE NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
) ENGINE=INNODB;
|
|
";
|
|
$pdo->exec($sql);
|
|
echo "Table 'missions' created successfully." . PHP_EOL;
|
|
|
|
// Add some initial data for demonstration
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM missions");
|
|
if ($stmt->fetchColumn() == 0) {
|
|
$pdo->exec("
|
|
INSERT INTO missions (name, drone, status, mission_date) VALUES
|
|
('Vineyard Survey', 'DJI Agras T30', 'Completed', '2025-09-25'),
|
|
('Pest Control', 'XAG P40', 'In Progress', '2025-09-27'),
|
|
('Crop Dusting', 'DJI Agras T30', 'Scheduled', '2025-09-29');
|
|
");
|
|
echo "Initial data inserted into 'missions' table." . PHP_EOL;
|
|
}
|
|
|
|
} catch (PDOException $e) {
|
|
die("DB ERROR: " . $e->getMessage());
|
|
}
|