-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
75 lines (61 loc) · 1.85 KB
/
index.php
File metadata and controls
75 lines (61 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
session_start();
include "db.php";
// Must be logged in
if (!isset($_SESSION['user'])) {
header("Location: login.php");
exit;
}
$message = "";
if (isset($_POST['add'])) {
$type = $_POST['type'];
$category = $_POST['category'];
$amount = $_POST['amount'];
$description = $_POST['description'];
$date = $_POST['date'];
$username = $_SESSION['user'];
if ($amount > 0) {
mysqli_query($conn,
"INSERT INTO transactions
(type, category, amount, description, created_at)
VALUES
('$type', '$category', '$amount', '$description', '$date')"
);
$message = "Transaction added successfully";
} else {
$message = "Amount must be greater than zero";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Add Transaction</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Add Income / Expense</h2>
<form method="POST">
<select name="type" required>
<option value="">Select Type</option>
<option value="income">Income</option>
<option value="expense">Expense</option>
</select>
<select name="category" required>
<option>Food</option>
<option>Travel</option>
<option>Rent</option>
<option>Entertainment</option>
<option>Other</option>
</select>
<input type="number" name="amount" placeholder="Amount" required>
<input type="text" name="description" placeholder="Description">
<input type="date" name="date" required>
<button name="add">Add Transaction</button>
</form>
<?php if ($message): ?>
<p style="text-align:center; color:white;"><?= $message ?></p>
<?php endif; ?>
<a href="dashboard.php" class="dashboard-btn">View Dashboard</a>
</body>
</html>