├── README.md ├── connection.php ├── customer.php ├── firsttime.php ├── include ├── footer.php └── header.php ├── index.php ├── js └── main.js ├── send.php └── transaction.php /README.md: -------------------------------------------------------------------------------- 1 | # Sparks Foundation - Basic Banking System 2 | 3 | ## Index 4 | - [Description](#Description) 5 | - First Time Installation 6 | - How To Run 7 | - Screenshort 8 | 9 | ## Description 10 | - This a Internship project by Sparks Foundation. 11 | - This project is built on HTML/CSS, Bootstrap, PHP and MySQL. 12 | - Details of Customers are maintained as `Name`, `Email`, `Amount` are fields. 13 | - Transaction is done through PDO, If some Error occured while Transaction changes made to table is Rollback(Reverted). 14 | 15 | ## First Time Installation 16 | - Clone the Repository. 17 | - Make sure you have installed XAMP on your computer. 18 | - Copy this folder(Sparks-Foundation) to XAMP installation Directory and then inside htdocs folder. 19 | 20 | ``` 21 | For Example 22 | C:\xampp\htdocs\ 23 | ``` 24 | - Open Xamp Control Panel. Click on Start button near Apache and MySQL. 25 | - Open browser type the following into search bar. 26 | ``` 27 | http://localhost/Sparks-Foundation/firsttime.php 28 | ``` 29 | - If everything works fine you would see this on your browser. 30 | ``` 31 | Conection was established Succesfully. 32 | DATABASE Created Successfully. 33 | Customer Table Created Successfully. 34 | Entries added to table Successfully. 35 | Transaction Table Created Successfully. 36 | ``` 37 | - This means that you have created a database name bank, a table name customers also added 10 entries to table and finally creating a table name Transaction. 38 | 39 | ## How To Run 40 | - After following steps above(First Time Installation). 41 | - Make Sure XAMP is active with Apache and MySQL Server Enabled. 42 | - Open Browser Enter the following URL: 43 | ``` 44 | http://localhost/Sparks-Foundation/ 45 | ``` 46 | OR 47 | ``` 48 | http://localhost/Sparks-Foundation/index.php 49 | ``` 50 | - You will land to Homepage of Money Bank Website. 51 | - Click On `View all Customer` from Navigation OR `Get Started` button for viewing detail of all Customers. 52 | - You will see Customer details in table with deatils like(Name, Email, Current balance, etc.). 53 | - Click on `Send` Button Corresponding Any row of table. 54 | - Now We are on Money Transfering Page. Now Enter a Valid Name in `To` textbox and also Enter Amount, Click on checkbox and finally Click on `Send` Button To Start Transfer. 55 | - Make sure the Amount you enter is not grator then current balance of the Person Selected, else it will pop Message. 56 | - If the Transaction is successful Message will displayed and Changes made by above Transaction will be updated to customer table. -------------------------------------------------------------------------------- /connection.php: -------------------------------------------------------------------------------- 1 | setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 25 | $db->begintransaction(); 26 | 27 | // checking for sufficient for transaction 28 | $sql = 'SELECT amount FROM customers WHERE Name=:from'; 29 | $stmt = $db->prepare($sql); 30 | $stmt->execute(array(":from" => $from)); 31 | $availableAmount = (int) $stmt->fetchColumn(); 32 | $stmt->closeCursor(); 33 | 34 | if ($availableAmount < $amount) { 35 | throw new Exception('Insufficient amount to transfer!'); 36 | } 37 | 38 | //Preparing SQL statements for transaction 39 | $st1 = $db->prepare( 40 | "update customers set 41 | `Amount`= Amount - :amt where Name = :fro " 42 | ); 43 | $st2 = $db->prepare( 44 | "update customers set 45 | `Amount`= Amount + :amt where Name = :to " 46 | ); 47 | 48 | $st3 = $db->prepare( 49 | "INSERT INTO `transaction` ( `From`, `To`, `Amount`) VALUES ( :from, :to, :amount)" 50 | ); 51 | 52 | //Assigning values to placeholder 53 | $st1->bindValue(':amt', $amount, PDO::PARAM_INT); 54 | $st1->bindValue(':fro', $from, PDO::PARAM_STR); 55 | $st2->bindValue(':amt', $amount, PDO::PARAM_INT); 56 | $st2->bindValue(':to', $to, PDO::PARAM_STR); 57 | $st3->bindValue(':amount', $amount, PDO::PARAM_INT); 58 | $st3->bindValue(':to', $to, PDO::PARAM_STR); 59 | $st3->bindValue(':from', $from, PDO::PARAM_STR); 60 | //Excecuting the SQL Queries 61 | $st1->execute(); 62 | $st2->execute(); 63 | $st3->execute(); 64 | //Checking if user name Exits 65 | if(!$st2->rowCount()||!$st1->rowCount()){ 66 | throw new Exception('User not Found!'); 67 | } 68 | 69 | //Checking if data is entered into transaction table 70 | if(!$st3->rowCount()) throw new Exception('Could not insert data into Transaction Entry!'); 71 | 72 | //Everything is fine so Commit the changes 73 | if($db->commit()) 74 | notification("success","Success","Transaction successfull."); 75 | else 76 | notification("danger","Error","Transaction failed!"); 77 | 78 | } catch (PDOException $e) { //PDO related Exceptions are handle here 79 | notification("danger","Error",$e->getMessage()); 80 | }catch(Exception $e){ //Custom Exceptions are handle here 81 | notification("danger","Error",$e->getMessage()); 82 | $db->rollBack(); //Reverting changes if any 83 | } 84 | } 85 | 86 | //Pops up notification about error or sucess messages 87 | function notification($type,$strong,$message){ 88 | echo ''; 92 | } 93 | 94 | ?> -------------------------------------------------------------------------------- /customer.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Customer Details 11 | 12 | 13 | 14 | 15 | 23 | 24 | 25 |
26 |

Customers Details

27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 0){ 43 | while($row = mysqli_fetch_assoc($result)){ 44 | echo " 45 | 46 | 47 | 48 | 49 | 50 | "; 51 | 52 | } 53 | }else{ 54 | echo ""; 55 | } 56 | ?> 57 | 58 |
#NameE-MailCurrent Balance
".$row['Cust_ID']."".$row['Name']."".$row['Email']."".$row['Amount']."
59 |
60 |
61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /firsttime.php: -------------------------------------------------------------------------------- 1 | "; 13 | } 14 | 15 | //Creating database bank 16 | $sql= "CREATE DATABASE Bank"; 17 | 18 | $result = mysqli_query($conn,$sql); 19 | 20 | if(!$result){ 21 | echo "Sorry we failed to create database.
"; 22 | }else{ 23 | echo "DATABASE Created Successfully.
"; 24 | } 25 | 26 | //Creating table customers 27 | $sql = "CREATE TABLE `bank`.`customers` ( `Cust_ID` INT NOT NULL AUTO_INCREMENT , `Name` VARCHAR(11) NOT NULL , `Email` VARCHAR(20) NOT NULL , `Amount` FLOAT(30) NOT NULL , PRIMARY KEY (`Cust_ID`)) "; 28 | 29 | $result = mysqli_query($conn,$sql); 30 | 31 | if(!$result){ 32 | echo "Sorry we failed to create table.
"; 33 | }else{ 34 | echo "Customer Table Created Successfully.
"; 35 | } 36 | 37 | //Adding 10 dummey data into table customers 38 | $sql ="INSERT INTO `bank`.`customers` (`Cust_ID`, `Name`, `Email`, `Amount`) VALUES ('1', 'harish', 'harish@yahoo.com', '3000.00'), ('2', 'shivam', 'shivam@orkut.com', '10000.00'), ('3', 'niladri', 'niladri@outlook.com', '5000.00'), ('4', 'raj', 'raj@gmail.com', '15000.00'), ('5', 'parkash', 'parkash@rediff.com', '20000.00'), ('6', 'kunal', 'kunal@xyz.com', '3500.00'), ('7', 'rahul', 'rahul@abc.com', '12000.00'), ('8', 'aryan', 'aryan@123.com', '30000.00'), ('9', 'chandan', 'chandan@gmail.com', '23000.00'), ('10', 'vikas', 'vikas@def.com', '40000.00')"; 39 | 40 | $result = mysqli_query($conn,$sql); 41 | 42 | if(!$result){ 43 | echo "Sorry we failed to add entries to table.
"; 44 | }else{ 45 | echo "Entries added to table Successfully.
"; 46 | } 47 | 48 | //Creating transaction table customers 49 | $sql = "CREATE TABLE `bank`.`transaction` ( `Tran_ID` INT NOT NULL AUTO_INCREMENT , `From` VARCHAR(11) NOT NULL , `To` VARCHAR(11) NOT NULL , `Amount` DECIMAL NOT NULL , PRIMARY KEY (`Tran_ID`))"; 50 | 51 | $result = mysqli_query($conn,$sql); 52 | 53 | if(!$result){ 54 | echo "Sorry we failed to create table.
"; 55 | }else{ 56 | echo "Transaction Table Created Successfully.
"; 57 | } 58 | 59 | ?> -------------------------------------------------------------------------------- /include/footer.php: -------------------------------------------------------------------------------- 1 | 2 | 10 | -------------------------------------------------------------------------------- /include/header.php: -------------------------------------------------------------------------------- 1 | 2 | 20 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Welcome to Money Bank 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 59 |
60 | 61 | 62 | 63 |
64 |
65 |

Our Services

66 |
67 |
68 |
69 |

Manage Everything at one place

70 |
71 |

To see all Customers

72 | 73 |
74 |
75 |

To see all Transaction

76 | 77 |
78 | 79 |
80 | 81 |
82 | ... 83 |
84 |
85 |
86 | 87 |
88 |
89 | 90 |
91 |

About Us

92 |
93 | 94 |
95 |
96 | 97 |
98 |
99 |

100 | Ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate 101 | velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in 102 | culpa qui officia deserunt mollit anim id est laborum. 103 |

104 | Learn More 105 |
106 |
107 | 108 |
109 |
110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /js/main.js: -------------------------------------------------------------------------------- 1 | //validating the send page 2 | document.querySelector("#submit").addEventListener("click", function(event) { 3 | 4 | //getting connnection to form textbox 5 | const form_txt = document.querySelector("#From"); 6 | const to_txt = document.querySelector("#To"); 7 | const amount_txt = document.querySelector("#Amt"); 8 | 9 | //checking if textbox is empty or not if empty prevent the submission of form 10 | if(form_txt.value ===""|| to_txt.value==="" || amount_txt.value===""){ 11 | alert("Error: Some of Fields are Empty!! ") 12 | event.preventDefault(); 13 | } 14 | else if(form_txt.value === to_txt.value){ //checking if names entered on textbox i.e. from and to if both are same so prevent the form submission 15 | alert("Error: Please Enter Another name!! ") 16 | event.preventDefault(); 17 | } 18 | else{ //Finally asking user to continue if yes then form submit else form wil not submitted 19 | const value = confirm("Are you sure you want to continue?"); 20 | if(!value) 21 | event.preventDefault(); 22 | } 23 | }, false); -------------------------------------------------------------------------------- /send.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Transfer Money 11 | 12 | 13 | 14 | 15 | 34 | 35 | 36 |
37 |

Transer Money

38 |
39 |
40 |
41 |
42 | 43 | 44 |
We'll never share your email with anyone else.
45 |
46 |
47 | 48 | 49 |
We'll never share your email with anyone else.
50 |
51 |
52 | 53 | 54 |
We'll never share your email with anyone else.
55 |
56 | 60 | 61 |
62 |
63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /transaction.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Showing Transactions details 11 | 12 | 13 | 14 | 15 | 23 | 24 | 25 |
26 |

Transaction details

27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 0){ 41 | while($row = mysqli_fetch_assoc($result)){ 42 | echo " 43 | 44 | 45 | 46 | 47 | "; 48 | 49 | } 50 | }else{ 51 | echo ""; 52 | } 53 | ?> 54 | 55 | 56 |
Transaction IDFromToAmount
".$row['Tran_ID']."".$row['From']."".$row['To']."".$row['Amount']."
57 | 58 |
59 |
60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | --------------------------------------------------------------------------------