<?php include "head.php"; ?>
<h2>Propose a New Law</h2>
<?php
$db = new PDO('sqlite:lawsite.db');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $title = trim($_POST['title']);
    $summary = trim($_POST['summary']);
    $content = trim($_POST['content']);
    $proposer = trim($_POST['proposer']);
    $og = trim($_POST['url']);

    if ($title && $content && $proposer) {
        $stmt = $db->prepare("INSERT INTO laws (title, summary, content, proposer, og) VALUES (?, ?, ?, ?, ?)");
        $stmt->execute([$title, $summary, $content, $proposer, $og]);
        echo "<p>Law proposed successfully!</p>";
    } else {
        echo "<p>Please fill in all required fields.</p>";
    }
}
?>
<form class="propose" method="post">
    <input type="text" name="proposer" placeholder="Your Name" required>
    <input type="text" name="title" placeholder="Law Title" required>
    <input type="text" name="url" placeholder="Original reddit link..." required>
    <textarea name="summary" placeholder="Law Summary" required></textarea>
    <textarea name="content" placeholder="Full Law Text" required></textarea>
    <button type="submit">Submit Law</button>
</form>
<?php include "foot.php"; ?>
