Home php HTML + PHP Calculator

HTML + PHP Calculator

Author

Date

Category

Studying PHP, I decided to write a simple calculator on PHP.
There are two INPUs for two values, select to select a mathematical operation and submit .
The question is, as using the select + option , you can send the value of the php mathematical operator and further organize the work of the calculator with the display on a separate page (result.php For example)

html:

& lt; form action = "result.php" method = "post" & gt;
  & lt; Input Type = "text" name = "first-value" & gt;
  & lt; select name = "Math-Op" & gt;
    & lt; optional = "addition" & gt; + & lt; / option & gt;
    & lt; optional = "subtraction" & gt; - & lt; / option & gt;
    & lt; optional = "Multiplication" & gt; × & lt; / option & gt;
    & lt; optional = "Division" & gt; ÷ & lt; / option & gt;
  & lt; / select & gt;
  & lt; Input Type = "Text" name = "Second-Value" & gt;
  & lt; Input Type = "submit" name = "submit" value = "Calculate!" & GT;
& lt; / form & gt;

Answer 1, Authority 100%

rude, but approximately:

$ result = 0;
If (ISset ($ _ post ['submit'])) {
  if ($ _post ['Math-Op'] == 'addition') {
    $ resulting = $ _post ['first-value'] + $ _post ['second-value'];
  } elseif ($ _POST ['Math-Op'] == 'subtraction') {
    $ resulting = $ _post ['first-value'] - $ _post ['second-value'];
  } elseif ($ _POST ['Math-Op'] == 'Multiplication') {
    $ resulting = $ _post ['first-value'] * $ _post ['second-value'];
  } elseif ($ _POST ['Math-Op'] == 'Division') {
    $ resulting = $ _post ['first-value'] / $ _post ['second-value'];
  }
  Echo $ Result;
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions