I have a sendmail.php script which evaluates whether or not certain pieces of information are available and/or are within the correct parameters. Within this code I have defined two variables :

$maxsamples = 3;
$minsamples = 1;

I also have another variable which is a summation of several variables, all of which are posted to this script with a numeric value between 1.01 and 1.17.

$results = $AXISR + $AXISF + $DPRIC + $DSBIC + $DSRIC + 									$DS5050 + $DS4060 + $DS6040 + $PBREG + $PBFINE + 									$PCDA + $PCSEL + $PCSMR + $PCMC + $TPBIC + $TPRIC + $TPPMC;

I'm trying to deploy the email if the $results are > $minsamples but < $maxsamples, since we only allow 3 samples and it's pointless to send the form if they don't select anything.

To evaluate this, I'm using an IF statement as follows:

if (($results < $maxsamples)&&($results > $minsamples)) {
echo "<h1>Thank you for your interest in our products.  Your samples should ship within 3-5 business days.</h1>";
mail($recipient, $subject, $msg, $mailheaders);
} else {
echo "<i>Oops.. we think you may have missed something, please use your browser's \"Back\" button to correct and resubmit your request for samples.<br /><br />Make sure of the following:<ul><li>Select no more than 3 (three) products.<li>Fill in all required contact information fields.</i></ul>";
};

For some reason this is not working as expected.

I've tried replacing the $maxsamples and $minsamples with real numbers and it still won't work. I'm even echoing on screen what each variable to make sure the values are as expected and they always print correctly.

I've defined all the variables, I think I'm using the correct comparison operators and syntax, but I'm missing something.

Any ideas? Thanks!

Recommended Answers

All 4 Replies

is $results a numeric value or is it being treated as a string?

What happens if you use

settype($result, "float");

before you call your if statement?

If this doesn't help, please could you explain how it is "not working as expected"?

P.s. This is a little off topic, but I would use &quot; inplace of \"

What does "not working as expected" mean exactly. What is the actual value of $results going into the comparison and what result do you get from the compare. Have you tried substituting a fixed value for $results? If that works, then there is some problem with what goes into / comes out of the addition.

Thank you both. You gave me some things to think about.

By "not working as expected" I mean that if they select 1-3 samples, then they get a big "Thank you...", but if they select none, or more than 3, they get an error. I was seeing the error every time, regardless of the number of selections.

I have added settype($results, "float"); as a line to my code. I also made sure to set the $maxsamples and $minsamples.

I then added an echo $results to the top and bottom of my code to see if they matched... they didn't. I had a lot of code in between, so I moved the mailer IF statement to the top of the code, just beneath where I calculate the $results. It worked!

So, if one of you has time to explain this to me... since I'm pretty new at PHP. Why would the value of $results get lost within the code. Like I mentioned above, at the top of my code the value of $results was calculating correctly, but towards the bottom of the code, it was not. What can I watch out for next time to make sure this doesn't happen again?

Thanks again, very much.

Is there another variable with the name $results in your code or in an included file? Also I think you might want to use >= and <= rather than > and < in your comparisons.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.