By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

No value when setting variables based on $_POST variable.

P: 34
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
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $color = $_POST["color"];   //$color = blue from form
  3. if($color=="blue") $amount=100;
  4. if($color=="green") $amount=90;
  6. $total = $amount * 2;
  8. echo $total;
  9. ?>
[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:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $color = $_POST["color"];  //$color = blue from form
  3. $value=3;
  4. if($color=="blue") $amount=100;
  5. if($color=="green") $amount=90;
  7. $total = $amount * 2;
  9. echo $total;
  10. ?>
I get a value for total to be 6.

May 18 '07 #1
Share this Question
Share on Google+
3 Replies

P: 26
make sure ur $color variable have right value,
because i think nothing error here

$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=="blue") $amount=100;
if($color=="green") $amount=90;

$total = $amount * 2;

echo $total;
May 18 '07 #2

Expert 5K+
P: 5,821
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.
May 18 '07 #3

P: 34
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.
May 19 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.