Thursday 7 May 2015

Click HTML button to call PHP function

This code for simple to click a html button to call php function

Eg:

<html>
        <body>
              <form action="TestingFile.php" method="post">
                        <input type="submit" name="calculate" value="add">
                        <input type="submit" name="calculate" value="subtract">
                        <input type="submit" name="calculate" value="multiply">
              </form>
        </body>
</html>

<?php

if(!isset($_POST['calculate']))
{
$_POST['calculate'] = "";
}

switch ($_POST['calculate'])
{

      case 'add':
                         echo "add";//add function here
                         break;

      case 'subtract':
                             echo "subtract";//add function here
                             break;

      case 'multiply':
                              echo "multiply";//add function here
                              break;
default :

                          echo "defalt";//add function here
}

?>

No comments:

Post a Comment