File "edit_harvest.php"

Full Path: /home/leadltht/fastlinkinternet.com/administrator/data-provider/admin/edit_harvest.php
File size: 3.34 KB
MIME-type: text/x-php
Charset: utf-8

<?php
// Database connection
$conn = new mysqli("server329", "leadltht_prazey1982", "prazey1982123456", "leadltht_fastlinkinternet");
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$message = '';

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $id = $_POST['id'];
    $harvested_date = $_POST['harvested_date'];
    $harvested_amount = $_POST['harvested_amount'];
    $remarks = $_POST['remarks']; // Get the remarks from the form

    $query = "UPDATE harvest_collection SET harvested_date = ?, harvested_amount = ?, remarks = ? WHERE id = ?";
    $stmt = $conn->prepare($query);
    $stmt->bind_param("sdsi", $harvested_date, $harvested_amount, $remarks, $id);

    if ($stmt->execute()) {
        $message = "Harvest record updated successfully.";
    } else {
        $message = "Error: " . $stmt->error;
    }

    $stmt->close();
}

if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $query = "SELECT * FROM harvest_collection WHERE id = ?";
    $stmt = $conn->prepare($query);
    $stmt->bind_param("i", $id);
    $stmt->execute();
    $result = $stmt->get_result();
    $record = $result->fetch_assoc();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Edit Harvest Record</title>
    <style>
        body {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin: 0;
            padding-top: 20px; /* Adjust this value to move the form higher or lower */
            font-size: 30px; /* Adjust this value to change the font size */
        }
        .container {
            text-align: center;
            margin-top: 50px;
        }
        form {
            display: inline-block;
            text-align: left;
        }
        .back-button {
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2>Edit Harvest Record</h2>
        <?php if (isset($message)) echo "<p>$message</p>"; ?>
        <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
            <input type="hidden" name="id" value="<?php echo $record['id']; ?>">
            
            <label for="harvested_date">Harvested Date:</label>
            <input type="date" id="harvested_date" name="harvested_date" value="<?php echo $record['harvested_date']; ?>" required><br><br>
            
            <label for="harvested_amount">Harvested Amount:</label>
            <input type="number" id="harvested_amount" name="harvested_amount" step="0.01" min="0" value="<?php echo $record['harvested_amount']; ?>" required><br><br>
            
            <label for="remarks">Remarks:</label>
            <input type="text" id="remarks" name="remarks" value="<?php echo htmlspecialchars($record['remarks']); ?>"><br><br>
            
            <input type="submit" value="Update Record">
        </form>
        <div class="back-button">
            <a href="https://fastlinkinternet.com/administrator/data-provider/admin/?page=view_harvests">
                <button type="button" style="padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;">Back to Harvest Collections</button>
            </a>
        </div>
    </div>
</body>
</html>

<?php
$conn->close();
?>