```php getConnection(); // Get storage locations for dropdown $locationsQuery = "SELECT * FROM storage_locations"; $locationsStmt = $connection->prepare($locationsQuery); $locationsStmt->execute(); $storageLocations = $locationsStmt->fetchAll(PDO::FETCH_ASSOC); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $userId = $_SESSION['user_id']; $locationFound = $_POST['locationFound'] ?? ''; $notes = $_POST['notes'] ?? ''; $itemDescription = $_POST['itemDescription'] ?? ''; $category = $_POST['category'] ?? ''; $storageLocationID = $_POST['storageLocationID'] ?? null; try { $connection->beginTransaction(); // Insert report $reportQuery = "INSERT INTO reports (userId, locationFound, notes) VALUES (:userId, :locationFound, :notes)"; $reportStmt = $connection->prepare($reportQuery); $reportStmt->bindParam(':userId', $userId); $reportStmt->bindParam(':locationFound', $locationFound); $reportStmt->bindParam(':notes', $notes); $reportStmt->execute(); $reportID = $connection->lastInsertId(); // Handle file upload $imagePath = null; if (isset($_FILES['itemImage']) && $_FILES['itemImage']['error'] === UPLOAD_ERR_OK) { $uploadDir = 'uploads/'; if (!is_dir($uploadDir)) { mkdir($uploadDir, 0755, true); } $fileExtension = pathinfo($_FILES['itemImage']['name'], PATHINFO_EXTENSION); $fileName = uniqid() . '.' . $fileExtension; $targetPath = $uploadDir . $fileName; if (move_uploaded_file($_FILES['itemImage']['tmp_name'], $targetPath)) { $imagePath = $targetPath; } } // Insert item $itemQuery = "INSERT INTO items (reportID, description, category, storageLocationID, imagePath) VALUES (:reportID, :description, :category, :storageLocationID, :imagePath)"; $itemStmt = $connection->prepare($itemQuery); $itemStmt->bindParam(':reportID', $reportID); $itemStmt->bindParam(':description', $itemDescription); $itemStmt->bindParam(':category', $category); $itemStmt->bindParam(':storageLocationID', $storageLocationID); $itemStmt->bindParam(':imagePath', $imagePath); $itemStmt->execute(); $itemID = $connection->lastInsertId(); // Create verification record $verificationQuery = "INSERT INTO verifications (reportID, itemID) VALUES (:reportID, :itemID)"; $verificationStmt = $connection->prepare($verificationQuery); $verificationStmt->bindParam(':reportID', $reportID); $verificationStmt->bindParam(':itemID', $itemID); $verificationStmt->execute(); // Create notification $notificationQuery = "INSERT INTO notifications (userId, message) VALUES (:userId, :message)"; $notificationStmt = $connection->prepare($notificationQuery); $message = "Your report #$reportID has been submitted and is pending verification."; $notificationStmt->bindParam(':userId', $userId); $notificationStmt->bindParam(':message', $message); $notificationStmt->execute(); $connection->commit(); $success = "Report submitted successfully! Your report ID is #$reportID"; } catch (Exception $e) { $connection->rollBack(); $error = "Error submitting report: " . $e->getMessage(); } } ?>