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

    Join Date
    Oct 2013
    Location
    India
    Posts
    1
    Rep Power
    0

    Need help to understand..


    i m new in php and it a calculator .why here don't use action and method attribute in <form> tag.explain it plz..


    <?php

    ini_set('display_errors',0);

    if( isset( $_REQUEST['calculate'] ))

    {

    $operator=$_REQUEST['operator'];

    if($operator=="+")

    {

    $add1 = $_REQUEST['fvalue'];

    $add2 = $_REQUEST['lvalue'];

    $res= $add1+$add2;

    }

    if($operator=="-")

    {

    $add1 = $_REQUEST['fvalue'];

    $add2 = $_REQUEST['lvalue'];

    $res= $add1-$add2;

    }

    if($operator=="*")

    {

    $add1 = $_REQUEST['fvalue'];

    $add2 = $_REQUEST['lvalue'];

    $res =$add1*$add2;

    }

    if($operator=="/")

    {

    $add1 = $_REQUEST['fvalue'];

    $add2 = $_REQUEST['lvalue'];

    $res= $add1/$add2;

    }

    if($_REQUEST['fvalue']==NULL && $_REQUEST['lvalue']==NULL)

    {

    echo "<script language=javascript> alert(\"Please Enter values.\");</script>";

    }

    else if($_REQUEST['fvalue']==NULL)

    {

    echo "<script language=javascript> alert(\"Please Enter First value.\");</script>";

    }

    else if($_REQUEST['lvalue']==NULL)

    {

    echo "<script language=javascript> alert(\"Please Enter second value.\");</script>";

    }

    }

    ?>

    <form>

    <table style="border:groove #00FF99">

    <tr>

    <td style="background-color:aqua; color:red; font-family:'Times New Roman'">Enter First Number</td>

    <td colspan="1">



    <input name="fvalue" type="text" style="color:red"/></td>

    <tr>

    <td style="color:burlywood; font-family:'Times New Roman'">Select Operator</td>

    <td>

    <select name="operator" style="width: 63px">

    <option>+</option>

    <option>-</option>

    <option>*</option>

    <option>/</option>

    </select></td>

    </tr>

    <tr>

    <td style="background-color:aqua; color:red; font-family:'Times New Roman'">Enter First Number</td>

    <td class="auto-style5">

    <input name="lvalue" type="text" style="color:red"/></td>



    </tr>

    <tr>

    <td></td>

    <td><input type="submit" name="calculate" value="Calculate" style="color:wheat;background-color:rosybrown" /></td>



    </tr>

    <tr>

    <td style="background-color:aqua;color:red">Output = </td>

    <td style="color:darkblue"><?php echo $res;?></td>



    </tr>

    </table>

    </form>


    </body>
    </html>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,455
    Rep Power
    594
    Please edit your post and enclose the code in [ PHP ] tags. See the sticky at the top of this forum that says READ THIS BEFORE POSTING.

    The reason they are not needed is because this script accepts the default values for them. Where did you get this code? I hope you are not trying to learn PHP by copying someone's bad code from the internet (this certainly qualifies).
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    189
    Rep Power
    0
    You need to learn some php before copying other's code. This code is worthless for what you want to do. Mainly because you are using PHP to determine if you need to send a JS error message which WILL NOT WORK.

IMN logo majestic logo threadwatch logo seochat tools logo