index - PHP Online
Form of PHP Sandbox
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
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.
Result of php executing
Full code of index.php
- #Abdul Khaliq 20188856
- #Mohammed Rauf 20188398
- <html><body>
- <table witdh=100%, border= normal>
- <tr>
- <th>Input Value</th>
- <th>Output Result</th>
- </tr>
- <tr><td>
- <form method='post' name="form1" action="">
- Basic Salary <input name='basic' /><br />
- Marital Status: <br />
- <input type='radio' name='ms' value='single' checked/> Single <br />
- <input type='radio' name='ms' value='married' /> Married <br />
- Extra: <br />
- <input type='checkbox' name='extra[]' value="200>Work on Weekend" /> Work on Weekend - BD 200 <br />
- <input type='checkbox' name='extra[]' value="100>Work Night Shift" /> Work Night Shift - BD 100 <br />
- <input type='checkbox' name='extra[]' value="400>Work Abroad" /> Work Abroad - BD 400 <br /> <br/>
- <input type='submit' value='Calculate Salary' name = 'main' /> <br /> <br/>
- <input type='checkbox' name='save'/> Save these Details <br/> <br/>
- </form>
- <form method='post' action='history.php'>
- <input type = 'submit' value = 'View History' name = 'hist' />
- </form>
- </td>
- <td>
- <?php
- extract($_POST);
- if (!empty($_POST))
- {
- if($ms == "single")
- $sal = 50 + (int)$basic;
- else
- $sal = 100 + (int)$basic;
- foreach($extra as $key){
- $temp = explode(">", $key);
- $sal += $temp[0];
- }
- echo "<li>Salary Details: Total Salary is BD$sal </li>";
- echo "<li>Extras: </li>";
- $counter = 0;
- foreach($extra as $key){
- $counter++;
- $temp = explode(">", $key);
- echo "          $counter. $temp[1] <br>";
- }
- date_default_timezone_set("Asia/Bahrain");
- $details['0'] = array(
- 'total' => $sal,
- 'date' => date('d/m/Y'),
- 'time' => date("h:i:sa"),
- 'extra[]' => $extra
- );
- $cookies = $_COOKIE['history'];
- $cookies = stripslashes($cookies);
- $array = json_decode($cookies, true);
- if(!empty($array!=null))
- $result = array_merge($array,$details);
- else
- $result = $details;
- if(isset($save)){
- //setcookie('historyDetails', null, -3600);
- setcookie("historyDetails", json_encode($result), time() + 604800);
- }
- }
- ?>
- </td></tr></table></body></html>
- <html>
- <body>
- <?php
- extract($_POST);
- $cookies = $_COOKIE['historyDetails'];
- $cookies = stripslashes($cookies);
- $array = json_decode($cookies, true);
- ?>
- <center><h3>Current History</h3></center>
- <br><br>
- Total
- Date
- Time
- Extras
- <?php
- $count=0;
- foreach ($array as $arr){
- echo "<tr>";
- foreach ($arr as $key){
- $count++;
- echo "<td>";
- if($count == 4)
- foreach ($key as $key2){
- $calc = explode(">", $key2);
- echo "$calc[1] <br>";
- $count = 0;
- }
- else
- echo "$key";
- echo "</td>";
- }
- $count = 0;
- echo "<tr>";
- }
- ?>
- <form action = 'index.php'>
- <button type = 'submit'>Go back</button>
- </form>
- </body>
- </html>