PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
todd2011
Forum Newbie
Posts: 9 Joined: Sat Apr 23, 2011 3:30 pm
Post
by todd2011 » Sun Apr 24, 2011 11:04 pm
Hi,,
I have 2 textboxes
if the user enters any value in both the textboxes then the total is $50.00 if the user enters a value in one of the textboxes
then the total is $25.00
so i am checking for blanks and zero's because if u dont enter any value and tab over the field then javascript function will add 0.00 to the textbox but if u dont enter any value in the textbox then its blank
so here is my code
Code: Select all
$txt1 = $_REQUEST['txtfixedprice'];
$txt2 = $_REQUEST['txtretailprice'];
if((is_null($txt1) || ($txt1 =="0.00"))
$setflag1 ="no value";
else
$setflag1 ="some value";
if((is_null($txt2) || ($txt2 =="0.00"))
$setflag2 ="no value";
else
$setflag2 ="some value";
If($setflag1 =="some value" && $setflag2 =="some value")
$txttotal ="50.00";
elseif($setflag1 =="some value" || $setflag2 =="some value")
$txttotal ="25.00";
echo $txttotal;
its not working can smeone tell me where i made a mistake
thanks
todd
danwguy
Forum Contributor
Posts: 256 Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA
Post
by danwguy » Sun Apr 24, 2011 11:28 pm
you need to add { and } to your if statements like this...
Code: Select all
$txt1 = $_REQUEST['txtfixedprice'];
$txt2 = $_REQUEST['txtretailprice'];
if((is_null($txt1) || ($txt1 =="0.00")) {
$setflag1 ="no value";
}
else {
$setflag1 ="some value";
}
if((is_null($txt2) || ($txt2 =="0.00")) {
$setflag2 ="no value";
}
else {
$setflag2 ="some value";
}
If($setflag1 =="some value" && $setflag2 =="some value") {
$txttotal ="50.00";
}
elseif($setflag1 =="some value" || $setflag2 =="some value") {
$txttotal ="25.00";
}
echo $txttotal;
danwguy
Forum Contributor
Posts: 256 Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA
Post
by danwguy » Sun Apr 24, 2011 11:34 pm
also I would change the last else if statement to reflect all scenarios so you don't get double values...
Code: Select all
$txt1 = $_REQUEST['txtfixedprice'];
$txt2 = $_REQUEST['txtretailprice'];
if((is_null($txt1) || ($txt1 =="0.00")) {
$setflag1 ="no value";
} else {
$setflag1 ="some value";
}
if((is_null($txt2) || ($txt2 =="0.00")) {
$setflag2 ="no value";
} else {
$setflag2 ="some value";
If($setflag1 =="some value" && $setflag2 =="some value") {
$txttotal ="50.00";
}
elseif(($setflag1 =="some value" && $setflag2 =="0.00") || ($setflag1 == "0.00" && $setflag2 == "some value")) {
$txttotal ="25.00";
}
echo $txttotal;
todd2011
Forum Newbie
Posts: 9 Joined: Sat Apr 23, 2011 3:30 pm
Post
by todd2011 » Mon Apr 25, 2011 8:04 am
Hi,
i tried this code
Code: Select all
$txt1 = $_REQUEST['txtfixedprice'];
$txt2 = $_REQUEST['txtretailprice'];
ech $txt1;
echo $txt2;
if((is_null($txt1) || ($txt1 =="0.00")) {
$setflag1 ="no value";
} else {
$setflag1 ="some value";
}
echo $setflag1;
but there is no output for setflag1
so there is syntax error in the if statement
can someone help m with it
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Mon Apr 25, 2011 8:56 am
It is false that curly braces are required for if-statements. Curly braces are required for if-statements that need to run more than one statement.
Your problem lies in mismatched parentheses. You have an extra starting parenthesis in your first and second if-statements.
CrowderSoup
Forum Newbie
Posts: 18 Joined: Thu Apr 21, 2011 2:56 pm
Location: Murray, UT
Post
by CrowderSoup » Mon Apr 25, 2011 10:31 am
superdezign wrote: It is false that curly braces are required for if-statements. Curly braces are required for if-statements that need to run more than one statement.
Your problem lies in mismatched parentheses. You have an extra starting parenthesis in your first and second if-statements.
Wishing there was a +1 button I could click next to this post.
Mismatched parenthesis are often the cause of if-statements breaking. Make sure to check that all the opening parenthesis have matching closing parenthesis.
todd2011
Forum Newbie
Posts: 9 Joined: Sat Apr 23, 2011 3:30 pm
Post
by todd2011 » Mon Apr 25, 2011 10:13 pm
thanks guys removed the parentheses and it worked.