Page 1 of 1

syntax problem

Posted: Sun Apr 24, 2011 11:04 pm
by todd2011
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

Re: syntax problem

Posted: Sun Apr 24, 2011 11:28 pm
by danwguy
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;

 

Re: syntax problem

Posted: Sun Apr 24, 2011 11:34 pm
by danwguy
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;

 

Re: syntax problem

Posted: Mon Apr 25, 2011 8:04 am
by todd2011
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

Re: syntax problem

Posted: Mon Apr 25, 2011 8:56 am
by superdezign
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.

Re: syntax problem

Posted: Mon Apr 25, 2011 10:31 am
by CrowderSoup
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.

Re: syntax problem

Posted: Mon Apr 25, 2011 10:13 pm
by todd2011
thanks guys removed the parentheses and it worked.

Re: syntax problem

Posted: Tue Apr 26, 2011 5:55 am
by superdezign
Any time. :)