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

  • Home
  • SEARCH
  • 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 8048439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:26:12+00:00 2026-06-05T06:26:12+00:00

When I input numeric value in Number 1 and Number 2, and press Add.

  • 0

When I input numeric value in Number 1 and Number 2, and press “Add”. It does not display the total added value. Please see my coding below. and advice me, what to is the problem, and what can be done.

<html>
<head>
<title>Simple Calculator</title>
<?php
    if(isset($_POST['submitted'])){
        if(is_numeric($_POST['number1']) && is_numeric($_POST['number2'])){
        $add = ($_POST['number1'] + $_POST['number2']);
            echo "Add: ".$_POST['number1']."+".$_POST['number2']."=";
            }
        }



?>
<script type="text/javascript">


</script>
</head>

<body>
<h1>Simple Calculator</h1>
<form action="simple_calculator.php" method="post">
<p>Number 1: <input type="text" name="number1" size="20" value="<?php if(isset($_POST['number1'])) echo $_POST['number1'];?>"/></p>
<p>Number 2: <input type="text" name="number2" size="20" value="<?php if(isset($_POST['number2'])) echo $_POST['number2'];?>"/></p>

          <input type="button" name="add" value="Add" />
          <input type="button" name="minus" value="Minus" />
          <input type="button" name="multiply" value="Multiply" />
          <input type="button" name="divide" value="Divide" />
          <input type="reset" name="rest" value="Reset" />
          <input type="hidden" name="submitted" value="TRUE" />


</form>

</body>
</html>
  • 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-06-05T06:26:14+00:00Added an answer on June 5, 2026 at 6:26 am
    1. You are echoing the result data into the <head>, so it will not be displayed.
    2. You forgot to echo $add.
    3. Your <input>s are of type button and not submit, so the form will not be submitted to the server.
    4. Because you are echoing the previously entered values into the form, <input type="reset"> will probably not do what you want/expect it to do. I think it would be better to implement this as another submit.
    5. Because this form affects only what the next page displays and does not make a permanent change to the server, you should use the GET method and not POST.

    Try this:

    <html>
      <head>
        <title>Simple Calculator</title>
        <script type="text/javascript"></script>
      </head>
      <body>
        <h1>Simple Calculator</h1>
        <form action="simple_calculator.php" method="get">
          <p>Number 1: <input type="text" name="number1" size="20" value="<?php if (isset($_GET['number1']) && !isset($_GET['reset'])) echo $_GET['number1'];?>"/></p>
          <p>Number 2: <input type="text" name="number2" size="20" value="<?php if (isset($_GET['number2']) && !isset($_GET['reset'])) echo $_GET['number2'];?>"/></p>
          <input type="submit" name="add" value="Add" />
          <input type="submit" name="minus" value="Minus" />
          <input type="submit" name="multiply" value="Multiply" />
          <input type="submit" name="divide" value="Divide" />
          <input type="submit" name="reset" value="Reset" />
          <input type="hidden" name="submitted" value="1" />
        </form>
        <?php
    
            if (isset($_GET['submitted']) && !isset($_GET['reset'])) {
    
                echo "<div>";
    
                if (is_numeric($_GET['number1']) && is_numeric($_GET['number2'])) {
    
                    if (isset($_GET['add'])) {
    
                        $result = $_GET['number1'] + $_GET['number2'];
                        echo "Add: ".$_GET['number1']." + ".$_GET['number2']." = ".$result;
    
                    } else if (isset($_GET['minus'])) {
    
                        $result = $_GET['number1'] - $_GET['number2'];
                        echo "Minus: ".$_GET['number1']." - ".$_GET['number2']." = ".$result;
    
                    } else if (isset($_GET['multiply'])) {
    
                        $result = $_GET['number1'] * $_GET['number2'];
                        echo "Multiply: ".$_GET['number1']." * ".$_GET['number2']." = ".$result;
    
                    } else if (isset($_GET['divide'])) {
    
                        $result = $_GET['number1'] / $_GET['number2'];
                        echo "Divide: ".$_GET['number1']." / ".$_GET['number2']." = ".$result;
    
                    }
    
                } else {
    
                    echo "Invalid input";
    
                }
    
                echo "</div>";
    
            }
    
        ?>
      </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Input textfield in AIR for iOS looks really ugly when it does not have
I am facing a problem to extract a particular numeric value from an input
I have an input box with a numeric value in it. When the user
I've been using the '-wap-input-format' CSS property to force to numeric input using *N.
How to have numeric keyboard popup to input in TextBox on Windows Mobile 6.53?
I'm trying to validate a input field with the JQuery validation plugin. The numeric
Input rz value In the head I have: Event.observe(window, 'load', function() { $$(input).each(function(field){ Event.observe(field,
Problem! I Have the following input (rules) from a flat file (talking about numeric
As the question says, for some reason my program is not flushing the input
I have my form elements here: <li><div id=formanswer1 class=clonedInput>Answer: <input type=text id=formanswer1 value= /></div></li>

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.