Guest User

Untitled

a guest
Jul 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. <?php
  2.  
  3. session_start(); // This must always come before any HTML or header data. ALWAYS, NO EXCEPTIONS.
  4.  
  5. ?>
  6.  
  7. <!DOCTYPE html>
  8.  
  9. <html>
  10. <head>
  11. <title>Balance Test</title>
  12. </head>
  13. <body>
  14.  
  15. <form name ="depositForm" action="index.php" method="post" >
  16. <input name="depositVal" type="text" size="4"/>
  17. <input name"depositSubmit" type="submit" value="Deposit" />
  18. </form>
  19.  
  20. <?php
  21.  
  22. if ($_SESSION['balance'] == null) { // If there's no session data for a balance...
  23. $_SESSION['balance'] = 0; // Create that session data
  24. }
  25.  
  26. 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
  27. $_SESSION['balance'] += $_POST['depositVal'];
  28. }
  29.  
  30. ?>
  31.  
  32. <p>Current Balance:
  33.  
  34. <?php
  35.  
  36. echo "$" . $_SESSION['balance'] . ".00";
  37.  
  38. ?>
  39.  
  40. </p>
  41.  
  42. </body>
  43. </html>
Add Comment
Please, Sign In to add comment