Problem with Form
Posted: Wed Nov 16, 2011 10:35 pm
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/
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);
?>