Guest User

Untitled

a guest
Jan 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. session_start(); // start PHP session!
  2.  
  3. header('Cache-Control: no-cache');
  4. header('Pragma: no-cache');
  5.  
  6. $pamountErrorMsg = "";
  7. $irateErrorMsg = "";
  8.  
  9. $btnCalculate = $_GET['btnCalculate'];
  10. $irate = $_GET['irate'];
  11. $pamount = $_GET['pamount'];
  12. $y2d = $_GET['y2d'];
  13. if(isset($btnCalculate))
  14. {
  15. if(strlen(trim($pamount)) <= 0)
  16. {
  17. $pamountErrorMsg = "Principal Amount cannot be empty";
  18. $irateErrorMsg = "";
  19. }
  20. else if(strlen(trim($irate)) <= 0)
  21. {
  22. $irateErrorMsg = "The interest rate cannot be empty";
  23. $pamountErrorMsg = "";
  24. }
  25. else
  26. {
  27. $_SESSION["pamount"] = $_GET["pamount"];
  28. $_SESSION["irate"] = $_GET["irate"];
  29. $_SESSION["y2d"] = $_GET["y2d"];
  30. header("Location: Lab3DisclamerZCL.php");
  31. exit( );
  32. }
  33. }
  34. ?>
  35.  
  36. <form method='get' action="Result.php">
  37. <table>
  38. <tr>
  39. <td>
  40. Principal Amount
  41. </td>
  42. <td>
  43. <input type='text' class='input' name='pamount' size='30' />
  44. </td>
  45. <td class='error'>
  46. <?php echo $pamountErrorMsg; ?>
  47. </td>
  48. </tr>
  49. <tr>
  50. <td>
  51. Interest Rate (%)
  52. </td>
  53. <td>
  54. <input type='text' class='input' name='irate' size='30' />
  55. </td>
  56. <td class='error'>
  57. <?php echo $irateErrorMsg; ?>
  58. </td>
  59. </tr>
  60. <tr>
  61. <td>
  62. Years to Deposite
  63. </td>
  64. <td>
  65. <select name='y2d' selected='5'>
  66. <option value='1'>1</option>
  67. <option value='2'>2</option>
  68. <option value='3'>3</option>
  69. <option value='4'>4</option>
  70. <option value='5' selected='selected'>5</option>
  71. <option value='6'>6</option>
  72. <option value='7'>7</option>
  73. <option value='8'>8</option>
  74. <option value='9'>9</option>
  75. <option value='10'>10</option>
  76. </td>
  77. </tr>
  78. <tr>
  79. <td>&nbsp;</td>
  80. <td>
  81. <input type='submit' class='button' name='btnCalculate' value='Calculate'/>&nbsp;&nbsp;
  82. <input type='reset' class='button' name='btnReset' value='Reset' />
  83.  
  84. </td>
  85. </tr>
  86. </table>
  87. </form>
  88.  
  89. <?php error_reporting(E_ALL); ?>
  90. <?php
  91. session_start(); // retrieve PHP session!
  92. header('Cache-Control: no-cache');
  93. header('Pragma: no-cache');
  94. if (!isset($_SESSION["name"]))
  95. {
  96. header("Location: Calculator.php");
  97. exit( );
  98. }
  99. if(!isset($_SESSION["pamount"]))
  100. {
  101. $pamount = $_SESSION["pamount"];
  102. }
  103. if(!isset($_SESSION["irate"]))
  104. {
  105. $irate = $_SESSION["irate"];
  106. }
  107. if(!isset($_SESSION["pamount"]))
  108. {
  109. $y2d = $_SESSION["y2d"];
  110. }
  111. ?>
  112. <html>
  113. <head>
  114. <title>Results</title>
  115. <link rel = "stylesheet" type = "text/css" href = "style.css" />
  116. </head>
  117. <body>
  118. <h3 class="distinct">Thank you <?php echo $_SESSION["name"]?>, for using out deposite calculation tool.</h3>
  119. <p>Following is the results of calculation </p>
  120. <form action='Result.php' method='post'>
  121. <table>
  122. <?php
  123.  
  124.  
  125. $pamount = $_SESSION["pamount"];
  126. $irate = $_SESSION["irate"];
  127. $y2d = $_SESSION["y2d"];
  128. $runningPrincipal = $pamount;
  129.  
  130. for($i = 1; $i <= $y2d; ++$i)
  131. {
  132. $interest = $runningPrincipal * $irate * 0.01;
  133.  
  134. printf("<tr><td>%s</td><td>$%.2f</td><td>$%.2f</td></tr>", $i, $runningPrincipal, $interest);
  135.  
  136. $runningPrincipal += $interest;
  137.  
  138. }
  139. ?>
  140. </table>
  141. </form>
  142. <?php session_destroy();?>
  143. </body>
  144. </html>
Add Comment
Please, Sign In to add comment