Skip to main content

Expense Tracker Web App Free Source Code

Language

This is an Expense Tracker Web App that tracks the way you spend your income. It's simple and easy to use. The application contains the CRUD Operations or (Create, Read, Update, and Delete). The system stores the categories of expenses along with the amount to spend. Every time you create or add a new expense record, the balance will automatically calculate to show you your balance for each category. All expense records added will be listed and can be deleted on the expense report page.

Features

  • Create New Expense Category
  • Update Category
  • List Expense Category
  • Add New Expense Record
  • Delete Expense Record
  • List All Expense Record

Sample Code

Script of saving the Expense Category in the database.

  1. <?php
  2. require_once('db_config.php');
  3.  
  4. if(isset($_POST['submit']) && !empty($_POST['amount']) && !empty($_POST['expense_category_name'])){
  5. // echo print_r($_POST);
  6. $amount = mysqli_real_escape_string($con,$_POST['amount']);
  7. $expense_category_name = mysqli_real_escape_string($con,$_POST['expense_category_name']);
  8. $created_at = date('Y-m-d');
  9.  
  10. $sql = "SELECT expense_category_name FROM expense_category_tbl WHERE expense_category_name = '$expense_category_name' ";
  11. $query = mysqli_query($con, $sql);
  12. if($one = mysqli_num_rows($query) == 1){
  13. echo '
  14. <script type="text/javascript">
  15. alert("'.ucfirst($expense_category_name).' already exist");
  16. </script>';
  17. header('expense_category.php');
  18. }
  19.  
  20.  
  21. $data = mysqli_query($con, "INSERT INTO expense_category_tbl(expense_category_name, created_at, amount) VALUES('".$expense_category_name."', '".$created_at."','".$amount."')");
  22. }
  23.  
  24. //if data inserted successfully
  25. if(@$data === TRUE)
  26. {
  27. echo '
  28. <script type="text/javascript">
  29. alert("Success!");
  30. </script>';
  31.  
  32. }
  33.  
  34. else{
  35. $message = "All fields are required";
  36. }
  37. ?>

Updating the Expense Category Details

  1. <?php
  2. require_once('db_config.php');
  3.  
  4. if(isset($_POST['submit']) && !empty($_POST['amount']) && !empty($_POST['expense_name'])){
  5.  
  6. $amount = mysqli_real_escape_string($con,$_POST['amount']);
  7. $expense_name = mysqli_real_escape_string($con,$_POST['expense_name']);
  8. $update = mysqli_query($con, "UPDATE expense_category_tbl SET amount = '".$amount."', expense_category_name= '".$expense_name."'
  9. WHERE expense_category_id = '".$expense_category_id."' ");
  10. if($update === TRUE)
  11. {
  12. echo '
  13. <script type="text/javascript">
  14. alert("Success!");
  15. window.location.replace("expense_category.php");
  16. </script>';
  17.  
  18. }
  19.  
  20. else{
  21. echo '
  22. <script type="text/javascript">
  23. alert("Error!");
  24. window.location.replace("update.php ");
  25. </script>';
  26. }
  27.  
  28. }
  29. ?>

Add New Expense

  1. <?php
  2. require_once('db_config.php');
  3.  
  4. //A function to get difference between to numbers
  5. function diff($a=0, $b=0){
  6. $c = ($a - $b);
  7. return $c;
  8. }
  9.  
  10.  
  11.  
  12. if(isset($_POST['submit']) && !empty($_POST['amount_spent']) && !empty($_POST['expense_category_id']) && !empty($_POST['expense_date'])
  13. && !empty($_POST['expense_description'])){
  14. $amount_spent = mysqli_real_escape_string($con,$_POST['amount_spent']);
  15. @$expense_date = mysqli_real_escape_string($con,$_POST['expense_date']);
  16. $expense_description = mysqli_real_escape_string($con,$_POST['expense_description']);
  17. $expense_category_id = mysqli_real_escape_string($con,$_POST['expense_category_id']);
  18. $created_at = date('Y-m-d');
  19. $zero ='0';
  20.  
  21. //get a particular row amount and expense_name
  22. $getAll = mysqli_query($con, "SELECT expense_category_name, amount FROM expense_category_tbl WHERE expense_category_id ='".$expense_category_id." ' ");
  23. while($row = mysqli_fetch_assoc($getAll))
  24. {
  25. $_amount = $row['amount']; //SET AMOUNT
  26. $_expense_category_name = $row['expense_category_name'];
  27. }
  28.  
  29. $getBal = mysqli_query($con, "SELECT expense_category_id, SUM(amount_spent) AS amount_spent FROM expense_tbl WHERE expense_category_id ='".$expense_category_id." ' GROUP BY expense_category_id ");
  30. $sum=0;
  31. while ($row = mysqli_fetch_assoc($getBal)){
  32. $_amount_spent = $row['amount_spent'];
  33. $sum += $_amount_spent;
  34. }
  35.  
  36. $sum;
  37.  
  38. $balance = $_amount - $sum;
  39.  
  40. if($balance < 0)
  41. {
  42. echo '
  43. <script type="text/javascript">
  44. confirm("You are spending too much on '.ucfirst($_expense_category_name).' ");
  45. </script>';
  46. }
  47.  
  48. $data = mysqli_query($con, "INSERT INTO expense_tbl(expense_category_id,expense_description,expense_date,created_at,deleted,amount_spent)
  49. VALUES('".$expense_category_id."','".$expense_description."','".$expense_date."','".$created_at."','".$zero."','".$amount_spent."')");
  50. }
  51.  
  52.  
  53. //if data inserted successfully
  54. if(@$data === TRUE)
  55. {
  56. echo '
  57. <script type="text/javascript">
  58. alert("Success!");
  59. </script>';
  60.  
  61. }
  62.  
  63. else{
  64. $message = "All fields are required";
  65. }
  66. ?>

The Source Code is free to download. Feel Free to download and modify the source code the way you wanted. This may help other programmers specially for those who are new in PHP Language.

How to Run

Requirements
  • Download and Install any local web server such as XAMPP/WAMP.
  • Download the provided source code zip file. (download button is located below)
Installation/Setup
  1. Open your XAMPP/WAMP's Control Panel and start the Apache and MySQL.
  2. Extract the downloaded source code zip file.
  3. If you are using XAMPP, copy the extracted source code folder and paste it into the XAMPP's "htdocs" directory. And If you are using WAMP, paste it into the "www" directory.
  4. Browse the PHPMyAdmin in a browser. i.e. http://localhost/phpmyadmin
  5. Create a new database naming expense_tracker.
  6. Import the provided SQL file. The file is known as expense_tracker.sql located inside the db_script folder.
  7. Browse the Expense Tracker Web Application in a browser. i.e. http://localhost/expense_tracker.

DEMO

I hope this will help you with what you looking for and you'll find something useful for your future projects. For any queries you can contact me @ [email protected]

Enjoy :)

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment