No value when setting variables based on $_POST variable.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gsherp
    New Member
    • May 2007
    • 34

    No value when setting variables based on $_POST variable.

    I have a html page with a drop menu
    select name=color
    (....a list of colors)
    I select the color to be blue.

    in my php code I have[code=php]
    <?php
    $color = $_POST["color"]; //$color = blue from form
    if($color=="blu e") $amount=100;
    if($color=="gre en") $amount=90;

    $total = $amount * 2;

    echo $total;
    ?>[/code]

    [Please use CODE tags when posting your source code. Thanks! --pbmods]

    I get no value for total.

    If I initialize $value=3; before the if statement:
    [code=php]
    <?php
    $color = $_POST["color"]; //$color = blue from form
    $value=3;
    if($color=="blu e") $amount=100;
    if($color=="gre en") $amount=90;

    $total = $amount * 2;

    echo $total;
    ?>[/code]

    I get a value for total to be 6.


    PLEASE HELP
    Last edited by pbmods; May 18 '07, 04:46 PM. Reason: Added code tags.
  • shidec
    New Member
    • May 2007
    • 26

    #2
    make sure ur $color variable have right value,
    because i think nothing error here

    [PHP]
    <?php
    $color = $_POST["color"]; //$color = blue from form
    print "color is : $color"; //just to make sure $color value
    print_r($_POST) ; //just to make sure $_POST value
    if($color=="blu e") $amount=100;
    if($color=="gre en") $amount=90;

    $total = $amount * 2;

    echo $total;
    ?>
    [/PHP]

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Changed thread title to better match contents.

      Heya, gsherp. Welcome to TSDN!

      Is your form using POST or GET to send its values?

      Try using $_REQUEST instead of $_POST.

      Comment

      • gsherp
        New Member
        • May 2007
        • 34

        #4
        it works now, but only after i type into another file and then cut and paste back into the original file....weird. AND i know i didn't mistype.

        Comment

        Working...