Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start(); // This must always come before any HTML or header data. ALWAYS, NO EXCEPTIONS.
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Balance Test</title>
- </head>
- <body>
- <form name ="depositForm" action="index.php" method="post" >
- <input name="depositVal" type="text" size="4"/>
- <input name"depositSubmit" type="submit" value="Deposit" />
- </form>
- <?php
- if ($_SESSION['balance'] == null) { // If there's no session data for a balance...
- $_SESSION['balance'] = 0; // Create that session data
- }
- if ($_POST && is_numeric($_POST['depositVal'])) { // Only run this code if there's POST data (ie, the user hit the button already) AND if it's a numeric value
- $_SESSION['balance'] += $_POST['depositVal'];
- }
- ?>
- <p>Current Balance:
- <?php
- echo "$" . $_SESSION['balance'] . ".00";
- ?>
- </p>
- </body>
- </html>
Add Comment
Please, Sign In to add comment