473,320 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

No value when setting variables based on $_POST variable.

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;
  5.  
  6. $total = $amount * 2;
  7.  
  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;
  6.  
  7. $total = $amount * 2;
  8.  
  9. echo $total;
  10. ?>
I get a value for total to be 6.


PLEASE HELP
May 18 '07 #1
3 1770
shidec
26
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=="blue") $amount=100;
if($color=="green") $amount=90;

$total = $amount * 2;

echo $total;
?>
[/PHP]
May 18 '07 #2
pbmods
5,821 Expert 4TB
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
gsherp
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

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

Similar topics

3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
2
by: Remco Groot Beumer | last post by:
Hello, I created a program in which I use modules and classmodules for setting my variables. For example when I need to set the customerID in a variable I use something like: ...
0
by: Robert Harty | last post by:
Hello all, I have a strange problem with a HtmlTable control, which is dynamically created based on the results of a query. Each row in the table has a LinkButton added to it. When I create...
5
by: Zach | last post by:
When it is being said that, "value types are created on the stack or inline as part of an object". If a value type is created in an object, and that object is being called, the value type in that...
3
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have...
3
by: vatsa | last post by:
Hi all, we can simply change value of PS1 from command prompt . but I want to change the value of PS1 from within a c program. i tried to do that using getenv & putenv. but it is n't...
7
by: amygdala | last post by:
Hi all, I'm starting this new project in which I'ld like to implement sort of a design pattern I have seen being used in the CodeIgniter framework. Basically, the site will examine the URI and...
8
by: sheldonlg | last post by:
I have a case where the session values appear to lose their value. I tracked it down with some print_r inserted. Here are the lines: print '<br 1: '; print_r($_SESSION); $adminLevel = $_POST;...
4
by: chrism | last post by:
Hello, I'm hoping someone can help me out here. I'm building a shopping cart using sessions, populating with $_POST values from a form. Code abbreviated below: check if form is submitted. if...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.