PHP/MySQL Simple Water Billing System

We will teach you how to create Simple Water Billing System. This simple system uses for recording the water consumption every month you use, it also creates and total all your consumption from your previous record to the present. You can also generate a report for the billing process of your records from the beginning you started using this system. This simple system compose of PHP, MySQL, Javascript and Bootstrap.

Sample Code

Billing.php - This script is for the Home page and for the other forms.
  1. <?php session_start();
  2. if(!isset($_SESSION['id'])){
  3.         echo '<script>windows: location="index.php"</script>';
  4.         }
  5. ?>
  6. <?php
  7. $session=$_SESSION['id'];
  8. include 'db.php';
  9. $result = mysql_query("SELECT * FROM user where id= '$session'");
  10. while($row = mysql_fetch_array($result))
  11.   {
  12.   $sessionname=$row['name'];
  13.   }
  14. ?>
  15. <!DOCTYPE html>
  16. <html>
  17. <head>
  18. <title>Simple Water Billing System</title>
  19. <link href="css/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
  20. <link href="css/facebox.css" media="screen" rel="stylesheet" type="text/css" />
  21. <script src="js/jquery1.js" type="text/javascript"></script>
  22. <script src="css/facebox.js" type="text/javascript"></script>
  23.   <script type="text/javascript">
  24.         jQuery(document).ready(function($) {
  25.           $('a[rel*=facebox]').facebox({
  26.                 loadingImage : 'src/loading.gif',
  27.                 closeImage   : 'src/closelabel.png'
  28.           })
  29.         })
  30.   </script>
  31. <script src="js/application.js" type="text/javascript" charset="utf-8"></script>       
  32. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  33. <title>Simple Water Billing System</title>
  34. </head>
  35. <body>
  36. <nav class="navbar navbar-default">
  37.         <div class="container-fluid">
  38.                 <div class="navbar-header">
  39.                         <a class="navbar-brand" href="https://www.sourcecodester.com">Sourcecodester</a>
  40.                 </div>
  41.                 <ul class="nav navbar-nav">
  42.                 <li class="active"><a href="billing.php">Home</a></li>
  43.                 <li><a href="bill.php">Billing</a></li>
  44.                 <li><a href="user.php">Users</a></li>
  45.                 <li><a href="addclient.php">Add Client</a></li>
  46.                 <li><a href="viewuser.php">View Client</a></li>
  47.                 <li><a href="logout.php">Logout</a></li>
  48.                 </ul>
  49.         </div>
  50. </nav>
  51. <h1 align="center">Simple Water Billing System</h1>
  52. </body>
  53. </html>
result Viewpayment.php - And this is for the viewing of payments and also a report that you can print it out or just called a receipt.
  1. <?php session_start();
  2. if(!isset($_SESSION['id'])){
  3.         echo '<script>windows: location="index.php"</script>';
  4.        
  5.         }
  6. ?>
  7. <?php
  8. include 'db.php';
  9. $id =$_REQUEST['id'];
  10. $result = mysql_query("SELECT * FROM bill where id='$id'");
  11. while($row = mysql_fetch_array($result))
  12.   {
  13.           $prev=$row['prev'];
  14.           $owners_id=$row['owners_id'];
  15.           $pres=$row['pres'];
  16.           $price=$row['price'];
  17.           $totalcons=$pres - $prev;
  18.           $bill=$totalcons * $price;
  19.           $date=$row['date'];
  20.  
  21.   }
  22. ?>
  23. <?php
  24. include 'db.php';
  25. $result = mysql_query("SELECT * FROM owners WHERE id  = '$owners_id'");
  26. $test = mysql_fetch_array($result);
  27. if (!$result)
  28.                 {
  29.                 die("Error: Data not found..");
  30.                 }
  31.                                 $id=$test['id'] ;
  32.                                 $fname= $test['fname'] ;                                       
  33.                                 $lname=$test['lname'] ;
  34.                                 $mi=$test['mi'] ;
  35.                                 $address=$test['address'] ;
  36.                                 $contact=$test['contact'] ;
  37.  
  38. ?>
  39. <?php
  40. $session=$_SESSION['id'];
  41. include 'db.php';
  42. $result = mysql_query("SELECT * FROM user where id= '$session'");
  43. while($row = mysql_fetch_array($result))
  44.   {
  45.   $sessionname=$row['name'];
  46.   }
  47. ?>
Paybill.php - And for paying of your bill from previous to present.
  1. <?php session_start(); ?>
  2. <?php
  3.   include 'db.php';
  4. $owner_id =$_REQUEST['id'];
  5. $result = mysql_query("SELECT * FROM owners WHERE id  = '$owner_id'");
  6. $test = mysql_fetch_array($result);
  7. if (!$result)
  8.                 {
  9.                 die("Error: Data not found..");
  10.                 }
  11.                                 $id=$test['id'] ;
  12.                                 $fname= $test['fname'] ;                                       
  13.                                 $lname=$test['lname'] ;
  14.                                 $mi=$test['mi'] ;
  15.                                 $address=$test['address'] ;
  16.                                 $contact=$test['contact'] ;
  17.  
  18. ?>
  19.   <h2 align="center">Client Bill</h2><hr>
  20. <h3>Name: <?php echo $fname.'&nbsp;' .$lname.'&nbsp;'.$mi;?></h3>
  21. <p><?php $date=date('y/m/d H:i:s');
  22.  echo $date;?></p>
  23.  <form method="post" action="addbill.php">
  24. <div>    
  25.   <table class="table" width="355px">
  26.     <thead>
  27.       <tr>
  28.   <input type="hidden" name="owners_id" value="<?php echo $id; ?>" />
  29.   <input type="hidden" name="date" value="<?php echo $date; ?>" />
  30.     <td width="118">Previous Reading:</td>
  31.     <td width="66"><input type="text" name="prev"  /></td>
  32.     <td>Cu.m</td>
  33.       </tr>
  34.     </thead>
  35.     <tbody>
  36.       <tr>
  37.      <td>Present Reading:</td>
  38.     <td><input type="text" name="pres"  /></td>
  39.     <td>Cu.m</td>
  40.      </tr>
  41.       <tr>
  42.      <td>Price/Cu.m</td>
  43.     <td><input type="text" name="price" value="10"  /></td>
  44.     <td>php</td>
  45.      </tr>
  46.       <tr>
  47.         <td><button type="submit" name="total" class="btn btn-default">ADD</button></td>
  48.       </tr>
  49.     </tbody>
  50.   </table>
  51. </div>
result Hope that you learn in this tutorial. And for more updates and programming tutorials don't hesitate to ask and we will answer your questions and suggestions. Don't forget to LIKE & SHARE this website.

Comments

sir pwede paki check nag sql my error po salamat Error SQL query: /*!40101 SET NAMES utf8mb4 */; MySQL said: Documentation #1115 - Unknown character set: 'utf8mb4' yan ang lalabas pag load ko nag database salamat...

di nman gumagana yung system

HEllo my name is asadbek and your name is what

Add new comment