| Linux premium274.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64 Path : /home/whagcoha/ledger.mwagalwaservices.com/ |
| Current File : /home/whagcoha/ledger.mwagalwaservices.com/addexpenses.php |
<?php
require 'dbconfig/db.php';
$success = $error = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$user_id = $_SESSION['gen256']['id'];
$category = $_POST['category'];
$amount = $_POST['amount'];
$date = $_POST['date'];
$notes = $_POST['notes'];
$categorytype = $_POST['categorytype'];
$saving = $_POST['saving'];
$saving = isset($_POST['saving']) ? 1 : 0;
$stmt = $conn->prepare("INSERT INTO expenses (user_id, category, categorytype, amount, date, notes,saving) VALUES (?, ?, ?, ?,? ,? , ?)");
if ($stmt) {
$stmt->bind_param("issdssi", $user_id, $category, $categorytype, $amount, $date, $notes, $saving);
if ($stmt->execute()) {
$success = "Expense recorded successfully!";
} else {
$error = "Execute failed: " . $stmt->error;
}
$stmt->close();
} else {
$error = "Prepare failed: " . $conn->error;
}
}
?>
<div class="container mt-5">
<h2 class="mb-4">Add Expense</h2>
<?php if (!empty($success)): ?>
<div class="alert alert-success"><?= htmlspecialchars($success) ?></div>
<?php elseif (!empty($error)): ?>
<div class="alert alert-danger"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<form method="POST" action="">
<div class="mb-3">
<label class="form-label">Category Description</label>
<input type="text" name="category" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Category Type</label>
<select class="form-control" name="categorytype" required>
<option value="Generic">Nothing To Select</option>
<?php
$user_id = $_SESSION['gen256']['id'];
$result = $conn->query("SELECT name FROM categories WHERE user_id = '$user_id'");
while ($row = $result->fetch_assoc()) {
echo '<option value="' . htmlspecialchars($row['name']) . '">' . htmlspecialchars($row['name']) . '</option>';
}
?>
</select>
</div>
<div class="mb-3">
<label class="form-label">Amount</label>
<input type="number" step="0.01" name="amount" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Date</label>
<input type="date" name="date" class="form-control" required>
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="loanCheck" name="saving" value="1">
<label class="form-check-label" for="loanCheck">Mark as Saving</label>
</div>
<div class="mb-3">
<label class="form-label">Notes</label>
<textarea name="notes" class="form-control" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-danger">Save Expense</button>
<li class="nav-item mt-4">
<a class="nav-link" href="index.php?p=viewexpenses">
<i class="fas fa-fw fa-folder"></i>
<span>View Expenses</span>
</a>
</li>
</form>
</div>