Simple addition function is php


/ Published in: PHP
Save to your folder(s)

Very basic dont judge!


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. if(isset($_POST['sum1']) && isset($_POST['sum2']))
  4. {
  5. $sum1 = $_POST['sum1'];
  6. $sum2 = $_POST['sum2'];
  7.  
  8. function add($sum1,$sum2)
  9. {
  10. $answer = $sum1 + $sum2;
  11.  
  12. if(!is_numeric($sum1) || !is_numeric($sum2))
  13. {
  14. return 'Please enter a number nob!';
  15. }
  16.  
  17. echo $sum1 . ' + ' . $sum2 . ' = ' . $answer;
  18. }
  19.  
  20. echo add($sum1,$sum2);
  21. }
  22.  
  23. ?>
  24.  
  25. <form method="post" action="#">
  26. <input type="text" name="sum1" value="" /><br />
  27. <input type="text" name="sum2" value="" /><br />
  28.  
  29. <input type="submit" name="submit" value="Add" />
  30. </form>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.