Page 1 of 1

Problem with Form

Posted: Wed Nov 16, 2011 10:35 pm
by vflflyer
I am new to php and I a trying to use the "if statement" but it seems no matter what I do it does not work. What I am trying to do is, if the return on investment is a negative value make it $0 instead. It worked for the return on investment as a pecentage but can't get it to work on the dollars.
Here is some code, in the "comments testing" you can see what I am trying to do. Here is a link to the form! http://www.inflatablemarketplace.com/roi/

Code: Select all

<?php

$daily_impressions = $_POST["daily_impressions"];

$program_name = $_POST["program_name"];

$percent_viewers = $_POST["percent_viewers"];

$percent_interested = $_POST["percent_interested"];

$percent_might_convince = $_POST["percent_might_convince"];

$average_margin = $_POST["average_margin"];

$monthly_advertising_cost = $_POST["monthly_advertising_cost"];


if ($_POST["submit"] == "Calculate" && (empty($daily_impressions) || empty($percent_viewers) || empty($percent_interested)  || empty($percent_might_convince)  || empty($average_margin)  || empty($monthly_advertising_cost)))
{
$emptyvar = 1;
}

if ($_POST["submit"] == "Calculate" && $emptyvar != 1)
{
$projected_return_percent = (($daily_impressions * ($percent_viewers / 100) * ($percent_interested / 100) * ($percent_might_convince / 100) * $average_margin * 30) - $monthly_advertising_cost) * 100 / $monthly_advertising_cost;

$projected_return_dollars = (($daily_impressions * ($percent_viewers/100) * ($percent_interested/100) * ($percent_might_convince/100) * $average_margin) * 30)- $monthly_advertising_cost;

$projected_return_percent = round($projected_return_percent, 2);
$projected_return_dollars = round($projected_return_dollars, 0);
}

// -------------start of testing -------------------------------------------------------------------------------------
if  ($projected_return_percent < 100){

	$projected_return_percent = 0;
}
if  ($projected_return_dollar < 1){

	$projected_return_dollar = 0;
}
// all this does is 0 out the return percent if there is a loss!
// -----------end of testing -------------------------------------------------------------------------------------------

$directory = $_SERVER['PHP_SELF'];

$directory = str_replace("/process.php", "", $directory);

?>

Re: Problem with Form

Posted: Thu Nov 17, 2011 6:49 am
by Celauran
Earlier on in the script, you defined the variable as $projected_return_dollars but you're checking if $projected_return_dollar (note the missing s) is < 1.

Re: Problem with Form

Posted: Thu Nov 17, 2011 10:08 am
by vflflyer
Celauran wrote:Earlier on in the script, you defined the variable as $projected_return_dollars but you're checking if $projected_return_dollar (note the missing s) is < 1.
Thanks, I can't believe I missed that. :)

Re: Problem with Form

Posted: Thu Nov 17, 2011 10:24 am
by vflflyer
That's funny when I put the "s" at the end of dollar and then load the form , it does not do the calculations at all. It is like the calculate button does not work anymore.

Am I using my if statements correctly?

Re: Problem with Form

Posted: Thu Nov 17, 2011 10:36 am
by Celauran
You added the missing "s" in 2 places, right? I don't see anything wrong with your if statements

Re: Problem with Form

Posted: Thu Nov 17, 2011 10:44 am
by vflflyer
Celauran wrote:You added the missing "s" in 2 places, right? I don't see anything wrong with your if statements
Yes, as you can tell I am new at this.

Code: Select all

// -------------start of testing -------------------------------------------------------------------------------------
if  ($projected_return_percent < 100){

	$projected_return_percent = 0;
}
if  ($projected_return_dollars < 0){

	$projected_return_dollars = 0;
}
// -----------end of testing -------------------------------------------------------------------------------------------