1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Rep Power

    Help with coding a simple calculator using PHP / HTML

    this link show the instructions. It is the second part of the assignment the first part looks the same but only had an add button with an ouptut. any help appreciated. thanks!


    I need help coding that in PHP I don't know how to do mutliple functions such as divide multiply. this is the code for when I had just and add function:

    $num1 = intval($_POST['value1']);
    $num2 = intval($_POST['value2']);

    $answer = "{$num1} + {$num2} = " . strval($num1 + $num2);
    <!doctype html>
    <html lang="eng">
    <meta charset="utf-8">

    <body style="background-color:lightgrey;">
    <div id="header">
    <hr />

    <div id="content">
    <form name="frmInput" action="add.php" method="post">
    <p>Number 1: <input type="text" name="value1" maxlength="100" size="50"></p>
    <p>Number 2: <input type="text" name="value2" maxlength="100" size="50"></p>
    <p><input type='submit' name='btnSubmit' value='Add'></p>

    <?php if(isset($answer)){print($answer);}?>

    <div id="footer">
    <hr />
    <cite>Created for MIS3501, Temple University, February 2013</cite>


  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Pennsylvania, USA
    Rep Power
    We're not going to keep doing your homework for you. That's not how you learn.

    Read up on the PHP switch() statement, or if/elseif.

    Also read the new user guide to learn how to post a question. Yours are poorly worded, unformatted, and break the forum rules.

    This thread is closed. Ask Professor Shafer if you can't figure it out. You're not going to have a very good time later in the year if you can't get these kinds of basic examples.

    And yes, I know your professor.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Washington, USA
    Rep Power
    Since you're in class and have access to a professor, ask him for advice. Yes we could help you, tell you how best to do this, but he is probably expecting that the assignment will look a certain way.

    But I'll still offer a tip: you can have multiple submit buttons on a form, and if you give them different names then you can tell which button the user clicked (look in $_POST).

    Comments on this post

    • ManiacDan agrees : Three minutes.

IMN logo majestic logo threadwatch logo seochat tools logo