Updating database with php

hello,
im trying to create a simple bank using php and sql, i need some help doing money transfer between users inside the database, so basically changing values within the database using an html input form. i need some help since i cant quite figure how it should look. here’s my code:

> <?php
> include('config.php');
> ?>
> <?php
> // Initialize the session
> session_start();
>  
> // Check if the user is logged in, if not then redirect him to login page
> if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
>     header("location: login.php");
>     exit;
> }
> ?>
>  
>  
>  <!DOCTYPE html>
> <html lang="en">
> <head>
>     <meta charset="UTF-8">
>     <title>Welcome</title>
>     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
>     <style type="text/css">
>         body{ font: 14px sans-serif; text-align: center; }
>     </style>
> </head>
> <body>
>     <div class="page-header">
>         <h1>Hi, <b><?php echo htmlspecialchars($_SESSION["username"]); ?></b>. Welcome to our site.</h1>
>     </div>
>     <p>
>         <a href="reset-password.php" class="btn btn-warning">Reset Your Password</a>
>         <a href="logout.php" class="btn btn-danger">Sign Out of Your Account</a>
>     </p>
> </body>
> </html>
>  
>  
>  
>  
> 
> <form action="changeinfo.php" method="post"> 
>     Change Username: <input type="text" name="username"><br/>
>     Change Password: <input type="text" name="password"><br/>
> 	 <input type="submit" value="Submit">
> 
> </form>
> 
> 
> 
> 	<h1>Transfer Money</h1>
> <form action="transfer.php" method="post">
>     ID: <input type="text" name = "field1" /><br/>
>     Amount: <input type="text" name = "field2" /><br/>
> 	
> 
>    <input type="submit" value="Send Money"  />
> </form>

Not really seeing enough to give you any help. What are your questions?

my question is: what is the code for changing the data in the database from an html input form…

There are countless examples posted on the web showing how to process form data using php. Some points you will want your form processing code to do -

  1. Detect that a post method form was submitted.
  2. Trim and validate all input data, storing any error messages in an array. This array will also serve as an error flag. If the array is empty, there are no errors. If the array is not empty, there are errors. You would validate that the fields are not empty and that the amount is a positive number greater than zero (if you don’t validate the sign of the amount, someone can ‘steal’ money from other accounts rather than to transfer money to other accounts.)
  3. If there are no validation errors use the submitted form data.
  4. Determine if the source user has at least the requested amount currently in his account (query the database table to get the current amount.)
  5. Start a transaction for the table holding the account records.
  6. Insert a row that subtracts the requested amount from the source user’s account.
  7. Insert a row that adds the requested amount to the destination user’s account.
  8. If no errors, commit the transaction.

You would also want to use a select/option menu, perhaps with javascript type-a-head/auto-suggest, to let you pick from existing users, to reduce the chance of typo mistakes. You would also want to query for and display the current source user account amount for reference.

Sponsor our Newsletter | Privacy Policy | Terms of Service