index - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of index.php

  1. #Abdul Khaliq 20188856
  2. #Mohammed Rauf 20188398
  3. <html><body>
  4. <table witdh=100%, border= normal>
  5. <tr>
  6. <th>Input Value</th>
  7. <th>Output Result</th>
  8. </tr>
  9. <tr><td>
  10. <form method='post' name="form1" action="">
  11. Basic Salary <input name='basic' /><br />
  12.  
  13. Marital Status: <br />
  14. <input type='radio' name='ms' value='single' checked/> Single <br />
  15. <input type='radio' name='ms' value='married' /> Married <br />
  16.  
  17. Extra: <br />
  18. <input type='checkbox' name='extra[]' value="200>Work on Weekend" /> Work on Weekend - BD 200 <br />
  19. <input type='checkbox' name='extra[]' value="100>Work Night Shift" /> Work Night Shift - BD 100 <br />
  20. <input type='checkbox' name='extra[]' value="400>Work Abroad" /> Work Abroad - BD 400 <br /> <br/>
  21.  
  22. <input type='submit' value='Calculate Salary' name = 'main' /> <br /> <br/>
  23.  
  24. <input type='checkbox' name='save'/> Save these Details <br/> <br/>
  25.  
  26. </form>
  27.  
  28.  
  29. <form method='post' action='history.php'>
  30.         <input type = 'submit' value = 'View History' name = 'hist' />
  31. </form>
  32. </td>
  33. <td>
  34. <?php
  35. extract($_POST);
  36.  
  37. if (!empty($_POST))
  38. {
  39.  
  40.         if($ms == "single")
  41.                 $sal = 50 + (int)$basic;
  42.         else
  43.                 $sal = 100 + (int)$basic;
  44.  
  45.         foreach($extra as $key){
  46.                 $temp = explode(">", $key);
  47.                 $sal += $temp[0];
  48.         }
  49.  
  50.         echo "<li>Salary Details: Total Salary is BD$sal </li>";
  51.         echo "<li>Extras: </li>";
  52.  
  53.         $counter = 0;
  54.  
  55.         foreach($extra as $key){
  56.                 $counter++;
  57.                 $temp = explode(">", $key);
  58.                 echo "&nbsp &nbsp &nbsp &nbsp &nbsp $counter$temp[1] <br>";
  59.         }
  60.  
  61.         date_default_timezone_set("Asia/Bahrain");
  62.  
  63.         $details['0'] = array(
  64.                 'total' => $sal,
  65.                 'date' => date('d/m/Y'),
  66.                 'time' => date("h:i:sa"),
  67.                 'extra[]' => $extra
  68.         );
  69.  
  70.         $cookies = $_COOKIE['history'];
  71.         $cookies = stripslashes($cookies);
  72.         $array = json_decode($cookies, true);
  73.  
  74.         if(!empty($array!=null))
  75.                 $result = array_merge($array,$details);
  76.         else
  77.                 $result = $details;
  78.  
  79.         if(isset($save)){
  80.                 //setcookie('historyDetails', null, -3600); 
  81.                 setcookie("historyDetails", json_encode($result), time() + 604800);
  82.         }
  83.  
  84. }
  85.  
  86. ?>
  87.  
  88. </td></tr></table></body></html>
  89.  
  90. <html>
  91. <body>
  92.  
  93. <?php 
  94.         extract($_POST);
  95.         $cookies = $_COOKIE['historyDetails'];
  96.         $cookies = stripslashes($cookies);
  97.         $array = json_decode($cookies, true);
  98. ?>
  99.  
  100.         <center><h3>Current History</h3></center>
  101.         <br><br>
  102.        
  103.        
  104.                
  105.                 Total
  106.                 Date
  107.                 Time
  108.           Extras
  109.                
  110.         <?php 
  111.                 $count=0;
  112.                 foreach ($array as $arr){
  113.                         echo "<tr>";
  114.                         foreach ($arr as $key){
  115.                                 $count++;
  116.                                 echo "<td>";
  117.                                 if($count == 4)
  118.                                         foreach ($key as $key2){
  119.                                                 $calc = explode(">", $key2);
  120.                                                 echo "$calc[1] <br>";
  121.                                                 $count = 0;
  122.                                         }
  123.                                 else
  124.                                         echo "$key";
  125.                                 echo "</td>";
  126.                         }
  127.                         $count = 0;
  128.                         echo "<tr>";
  129.                 }
  130.         ?>
  131.        
  132.         <form action = 'index.php'>
  133.                 <button type = 'submit'>Go back</button>
  134.         </form>
  135. </body>
  136. </html>
  137.  
File Description
  • index
  • PHP Code
  • 21 Mar-2021
  • 2.65 Kb
You can Share it: