Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6878913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:46:55+00:00 2026-05-27T04:46:55+00:00

So I have a simple site that is using php to do some simple

  • 0

So I have a simple site that is using php to do some simple math like so:

<form action="" method="POST">
<input type="text" name="first" />
<select name="method">
    <option>+</option>
    <option>_</option>
    <option>*</option>
    <option>/</option>
</select>
<input type="text" name="second" />
<input type="submit" value="Equals" />

The site lets the user inputs two numbers and then select a math operator to manipulate them by. So for example in the first input, the user could enter the number 3, select the subtraction operator, enter the number 1 in the next field and submit. I process the information like so:

if (isset($_POST['first']) && isset($_POST['second'])) {
   $first = $_POST['first'];
   $second = $_POST['second'];
   $method = $_POST['method'];
} 

However, I want to echo the result of the math problem on webpage after submitting. How would I do this? Just echoing all the variables would just give me (in this case) “3-1” instead of the actual answer which would be “2”.

Any idea how would accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:46:56+00:00Added an answer on May 27, 2026 at 4:46 am
    if (isset($_POST['first']) && isset($_POST['second'])) {
        $first = $_POST['first'];
        $second = $_POST['second'];
        $method = $_POST['method'];
        switch($method)
        {
            case '+':
                $result = $first + $second;
                break;
            case '-':
                $result = $first - $second;
                break;
            case '*':
                $result = $first * $second;
                break;
            case '/':
                // check for division by 0 (wouldn't want to blow anything up)
                $result = $first / $second;
                break;
            default:
                $result = 'undefined operation';
                break;
        }
        printf("%.5f %s %.5f = %s", $first, $method, $second, $result);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm using Moscow ML combined with CGI. I have a site that calculates simple
I have a simple Tray icon program that opens a site using System.Diagnostics.Process.Start(URL) And
I have a site that has a simple HTML button in a form. All
i have a site with a simple PHP-Navigation (using $_GET-Variables). HTML-code for navigation links
I currently have a very simple intranet that we are using for some basic
I have a relatively simple site that I'm working up for an intranet environment.
Lets say I have a simple ecommerce site that sells 100 different t-shirt designs.
I have a very simple sinatra site that I'm trying to access via ajax
I have a very simple MVC site that is returning a 404 not found
Imagine that you have a simple site with only 2 pages: login.aspx and secret.aspx.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.