Problem with Form

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

Post Reply
vflflyer
Forum Newbie
Posts: 11
Joined: Wed Nov 16, 2011 9:41 am

Problem with Form

Post 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);

?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Problem with Form

Post 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.
vflflyer
Forum Newbie
Posts: 11
Joined: Wed Nov 16, 2011 9:41 am

Re: Problem with Form

Post 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. :)
vflflyer
Forum Newbie
Posts: 11
Joined: Wed Nov 16, 2011 9:41 am

Re: Problem with Form

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Problem with Form

Post by Celauran »

You added the missing "s" in 2 places, right? I don't see anything wrong with your if statements
vflflyer
Forum Newbie
Posts: 11
Joined: Wed Nov 16, 2011 9:41 am

Re: Problem with Form

Post 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 -------------------------------------------------------------------------------------------
Post Reply