PHP taking "" for "0"

Discussion in 'Programming' started by godfer, May 23, 2010.

  1. #1
    Hi,

    I'm a beginner with PHP and have a problem:

    I have a simple HTML form which has only one field. One of the values that users can input is "zero". But, when the .PHP page that handles the form is called , the value "zero" comes immediatly, before the user enter any value, the output takes the "zero" into account and outputs a "result".

    Could someone please help me on that?

    Thanks. Best regards.

    Godefr
     
    godfer, May 23, 2010 IP
  2. wmhelp

    wmhelp Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can you post your PHP code?
     
    wmhelp, May 24, 2010 IP
  3. godfer

    godfer Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi wmhelp

    Thank you for your answer,

    here's the code:
    <?php
    $angle = $_POST['angle'];

    $radians = $angle*3.14159/180; $tang = tan($radians) ; $cotangent = 1/$tang;

    if($angle == "") echo "THE VALUE OF THE ANGLE?";
    if(($angle == 180) OR ($angle == 360) OR ($angle == -180) OR ($angle == -360) OR ($angle == 0)) echo "THE COTANGENT OF ", $angle, " DEGREES, IS ", "&#8734;"; else echo "THE COTANGENT OF ", $angle, " DEGREES, IS ", $cotangent;
    ?>


    When the page is loaded the answer comes as if "zero" had been inputed.
    Your help is greatly appreciated.

    Thank you.
     
    godfer, May 24, 2010 IP
  4. wmhelp

    wmhelp Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try intval() around your POST variable:
    $angle = intval($_POST['angle']);
     
    wmhelp, May 24, 2010 IP
  5. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #5
    wmhelp +1 :):)
     
    bartolay13, May 24, 2010 IP