Posted By

JonnySnip3r on 04/08/11


Tagged


Versions (?)

Simple calculate script


 / Published in: PHP
 

Simple as pie and chips...

  1. <?php
  2.  
  3. if(isset($_POST['sum1']) && isset($_POST['sum2']) && isset($_POST['calculate']))
  4. {
  5. $sum1 = strip_tags($_POST['sum1']);
  6. $sum2 = strip_tags($_POST['sum2']);
  7. $task = $_POST['calculate'];
  8.  
  9. if(!is_numeric($sum1) || !is_numeric($sum2))
  10. {
  11. echo 'Fuck you, you dirty little cunt!';
  12. }
  13. else
  14. {
  15. switch($task)
  16. {
  17. case 'add':
  18. echo $sum1 . ' + ' . $sum2 . ' = ' . $sum1 + $sum2;
  19. break;
  20. case 'multiply':
  21. echo $sum1 . ' x ' . $sum2 . ' = ' . $sum1 * $sum2;
  22. break;
  23. case 'subtract':
  24. echo $sum1 . ' - ' . $sum2 . ' = ' . $sum1 - $sum2;
  25. break;
  26. default:
  27. echo 'Get fucked!';
  28. break;
  29. }
  30. }
  31. }
  32.  
  33. ?>
  34.  
  35. <form method="post" action="#">
  36.  
  37. <p>
  38. <label>First Number: </label>
  39. <input type="text" name="sum1" value="" />
  40. </p>
  41.  
  42. <p>
  43. <select name='calculate'>
  44. <option value='null'>Choose...</option>
  45. <option value='add'>+</option>
  46. <option value='multiply'>x</option>
  47. <option value='subtract'>-</option>
  48. </select>
  49. </p>
  50.  
  51. <p>
  52. <label>Second Number: </label>
  53. <input type="text" name="sum2" value="" />
  54. </p>
  55.  
  56. <p>
  57. <input type="submit" name="submit" value="Calculate" />
  58. </p>
  59. </form>

Report this snippet  

You need to login to post a comment.