0% found this document useful (0 votes)
26 views3 pages

Fruit Harvest Guide With Code

This guide provides instructions for creating a Fruit Harvest Management System using PHP and MySQL, covering database setup, adding, editing, and deleting harvest data. It includes code snippets for the main functionalities such as displaying and managing fruit records. The project can be expanded with additional features like user authentication and data export options.

Uploaded by

jezzmarc882
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Fruit Harvest Guide With Code

This guide provides instructions for creating a Fruit Harvest Management System using PHP and MySQL, covering database setup, adding, editing, and deleting harvest data. It includes code snippets for the main functionalities such as displaying and managing fruit records. The project can be expanded with additional features like user authentication and data export options.

Uploaded by

jezzmarc882
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Fruit Harvest Management System - PHP & MySQL Guide

1. Introduction
This guide will help you create a PHP & MySQL-based Fruit Harvest Management System to
add, edit, delete, and search harvest data. It will also compute a grand total.

2. Database Setup

Run the following SQL script in phpMyAdmin to create the database and table:

CREATE DATABASE fruit_harvest;


USE fruit_harvest;

CREATE TABLE fruits (


id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
harvest1 INT,
harvest2 INT,
total INT
);

3. index.php - Display and Add Fruits

<?php
$conn = new mysqli('localhost', 'root', '', 'fruit_harvest');

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$harvest1 = $_POST['harvest1'];
$harvest2 = $_POST['harvest2'];
$total = $harvest1 + $harvest2;
$conn->query("INSERT INTO fruits (name, harvest1, harvest2, total) VALUES ('$name',
$harvest1, $harvest2, $total)");
}
$result = $conn->query('SELECT * FROM fruits');
?>

<form method='POST'>
Name: <input type='text' name='name' required>
Harvest 1: <input type='number' name='harvest1' required>
Harvest 2: <input type='number' name='harvest2' required>
<button type='submit'>Add</button>
</form>
<table border='1'>
<tr><th>Name</th><th>Harvest 1</th><th>Harvest 2</th><th>Total</th><th>Action</th></tr>
<?php while ($row = $result->fetch_assoc()) { ?>
<tr>
<td><?= $row['name'] ?></td>
<td><?= $row['harvest1'] ?></td>
<td><?= $row['harvest2'] ?></td>
<td><?= $row['total'] ?></td>
<td><a href='edit.php?id=<?= $row['id'] ?>'>Edit</a> | <a
href='delete.php?id=<?= $row['id'] ?>'>Delete</a></td>
</tr>
<?php } ?>
</table>

4. edit.php - Update Harvest Data

<?php
$conn = new mysqli('localhost', 'root', '', 'fruit_harvest');
$id = $_GET['id'];
$row = $conn->query("SELECT * FROM fruits WHERE id=$id")->fetch_assoc();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$harvest1 = $_POST['harvest1'];
$harvest2 = $_POST['harvest2'];
$total = $harvest1 + $harvest2;
$conn->query("UPDATE fruits SET name='$name', harvest1=$harvest1,
harvest2=$harvest2, total=$total WHERE id=$id");
header('Location: index.php');
}
?>

<form method='POST'>
Name: <input type='text' name='name' value='<?= $row['name'] ?>' required>
Harvest 1: <input type='number' name='harvest1' value='<?= $row['harvest1'] ?>'
required>
Harvest 2: <input type='number' name='harvest2' value='<?= $row['harvest2'] ?>'
required>
<button type='submit'>Update</button>
</form>

5. delete.php - Delete Harvest Record

<?php
$conn = new mysqli('localhost', 'root', '', 'fruit_harvest');
$id = $_GET['id'];
$conn->query("DELETE FROM fruits WHERE id=$id");
header('Location: index.php');
?>

6. Conclusion

This project demonstrates a CRUD system in PHP & MySQL. You can expand it by adding user
authentication, exporting data to CSV/PDF, or building a REST API.

You might also like