Create your own Bank System Version 2

This is a simple Bank script for a Simple User system that has a money system. Have a look, learn some, get smarter Image Not Found


CODE
<?php
/*
Simple Bank Script by Demonic
*/
##########
##Special Notes:
##edit the `cash` column name to fit your needs and the users table to fit your needs of your table name
#########
########SQL##################
#ALTER TABLE users ADD bank INT(255) DEFAULT 0;
#
#if your users table isn't called table change it same goes for your points system
########Connect to your database##########
include ("database.php");
#########End Database include############

###Set up some varibles###

$username $logged[username];//this is the cookie of the loggedin username.
$update_bank $_POST['bank'];//submit button.
$selection $_POST['addtobank'];
###end the varible checks etc..##

      
if($username){
        
        
//if the update bank button was pressed update bank total
        
if($update_bank){    
        

        
//selects the total bank,cash ammount from database.
        
$bank_total mysql_query("SELECT `cash`,`bank` FROM users WHERE username='".$username."' ") or die(mysql_error());
            
//gets the array of money from the users table of cash,bank total    
            
$totalb mysql_fetch_array($bank_total);

        
//check to see if the ammount of cash you set is more then you have

        
if($selection $totalb[cash]){
            
            die(
"You don't have that much money to put in bank");//show the error name
        
}

        
$totalcash $totalb[cash]-$selection;//subtracts the total of cash
        
$totalbank $totalb[bank]+$selection;//adds to the total in the bank

        //update the cash and bank total
        
        
$update_the_totals mysql_query("UPDATE `users` SET `bank` = '$totalbank', `cash` = '$totalcash' WHERE username='$username' ") or die(mysql_error());

        
//tell us we're done.

        
echo ("Your Bank and cash were updated. Cash Before: ".$totalb[cash]." Cash After: ".$totalcash.",Bank Before: ".$totalb[bank]." Bank After ".$totalbank."");
        

        
//elseif the button wasn't submited

        
}else{
        
        
//select data from the DB to show current money.

        
$total_all_together mysql_query("SELECT `cash`,`bank` FROM users WHERE username='".$username."' ") or die(mysql_error());
        
$total_currently mysql_fetch_array($total_all_together);

            echo (
"
                <h1>Total cash:"
.$total_currently[cash]." Total Bank: ".$total_currently[bank]."</h1>
                <form method='post'>
                <input type='text' name='addtobank' /><input type='submit' name='bank' value='Update Bank' />
                </form>
            "
);
        

        }
//end else

    
}//end if

    
else{//else tell them to login.


    
echo ("please login to add money to the bank");

    }
//end else
    

?>

Sunday May 27, 2007 | http://www.totaldream.org/article/31-create_your_own_bank_system_version_2.html