Jump to content

PHP Form calculating issue


JimKI

Recommended Posts

Is this still the code you're using for the calculations which produced the output you pasted above:

//get values from the $_post array:$totalRev = $_POST['revenue'];echo "totalRev: ".$totalRev."<br />";$vCost = $_POST['cost'];echo "vCost: ".$vCost."<br />";$overheadCost = $_POST['overhead'];echo "overheadCost: ".$overheadCost."<br />";$taxes = $_POST['taxes'];echo "taxes: ".$taxes."<br />";$otherIncome = $_POST['other']; echo "other: ".$other."<br />";//Calculate the gross profit:$gross = $totalRev - $vCost;echo "gross: ".$gross."<br />";//Calculate the net profit:$netProfit = $gross - $overheadCost;echo "netProfit: ".$netProfit."<br />";// Calculate Income after taxes:$afterTaxes = $netProfit - $taxes;echo "afterTaxes: ".$afterTaxes."<br />";// Calculate the Total Income:$totalIncome = $afterTaxes + $otherIncome; echo "totalIncome: ".$TotalIncome."<br />";

Link to comment
Share on other sites

I'm not sure why this is so difficult. Let me try to explain with an analogy:You're dealing with a calculation here, and there are certain values that go into the calculation. You're saying that you submit the values, but the result of the calculation is still 0. We're trying to get you to verify that the values that PHP is using in the calculation are the same values that you typed into the form. We're telling you to print the values out in the PHP script so that you can verify that it's using the correct values, but apparently you're not doing that.These are the steps in debugging this problem. You can't do one step until the previous ones are complete:1. Verify the values being used in the calculation.2. Verify the calculation is correct.3. Verify the answer is being displayed correctly.Again, we're over 20 posts in and we're still stuck on step 1. If you go back to the first reply to your question, you'll see that from the beginning we've been trying to get you to verify the values that PHP is actually using. Not what you think it's using, what it is actually using. You need to print those variables out and verify that they are the correct values you typed in. Once you do that then we can move on.edit: I can see we're making progress
already past that point I know where the errors are just don't understand why everything shows in the form after calculation except gross, after taxes and net income and why net income does not add since all the other things are working. check my last post you will see i did step 1
Link to comment
Share on other sites

Is this still the code you're using for the calculations which produced the output you pasted above:
//get values from the $_post array: $totalRev = $_POST['revenue']; echo "totalRev: ".$totalRev."<br />"; $vCost = $_POST['cost']; echo "vCost: ".$vCost."<br />"; $overheadCost = $_POST['overhead']; echo "overheadCost: ".$overheadCost."<br />"; $taxes = $_POST['taxes']; echo "taxes: ".$taxes."<br />"; $otherIncome = $_POST['other'];  echo "other: ".$other."<br />";[b]This Is the code now[/b]<?php//this is the top of your page, start of the scriptvar_dump($_POST);echo '<br/>';echo 'Revenue: ' . $_POST['revenue'] . '<br/>';echo '<br/>';echo 'Cost: ' . $_POST['cost'] . '<br/>';		// NAME STEP AND GIVE VALUE TO QUESTION VARIABLES SO ERROR CHECKING DOES NOT HAVE TO BE RECREATED FOR EVERY PAGE	$stepNumber = '4i';	$numQuestions = '9';		//get values from the $_post array:	$totalRev = $_POST['revenue'];	echo "totalRev: ".$totalRev."<br />";	$vCost = $_POST['cost'];	echo "vCost: ".$vCost."<br />";	 $overheadCost = $_POST['overhead'];	echo "overheadCost: ".$overheadCost."<br />";	$taxes = $_POST['taxes'];	   echo "taxes: ".$taxes."<br />";	  $otherIncome = $_POST['other'];  	echo "other: ".$other."<br />";	//Calculate the gross profit:	$gross = $totalRev - $vCost;	echo "gross: ".$gross."<br />";	//Calculate the net profit:	$netProfit = $gross - $overheadCost;	echo "netProfit: ".$netProfit."<br />";			// Calculate Income after taxes:		$afterTaxes = $netProfit - $taxes;		echo "afterTaxes: ".$afterTaxes."<br />";			  // Calculate the Total Income:		$totalIncome = $afterTaxes + $otherIncome; 		echo "totalIncome: ".$totalIncome."<br />";	// Print out the results	print ' <table border="1" cellpadding="4" cellspacing="3" width="350">		<tr>			<td align="left" valign="top" border="1">					Total Revenue</td><td><input type="text" style="40"		 name="revenue" value="'.$totalRev.'"> 									</td>			</tr>						<tr>		  <td align="left" valign="top" border="1">					Less: Variable Cost</td><td><input type="text" style="40" name="cost" value="'.$vCost.'"> 									</td>			</tr>						<tr>			<td align="left" valign="top" border="1">					Gross profit</td><td><input type="text" style="40" name="gross" value="'.$GrossProfit.'">									</td>			</tr>			<tr>			<td align="left" valign="top" border="1">					Less: Overhead Cost</td><td>					<input type="text" style="40" name="overhead" value="'.$overheadCost.'">				</td>			</tr>						<tr>			<td align="left" valign="top" border="1">					Net Profit</td><td>					<input type="text" style="40" name="netProfit" value="'.$netProfit.'">				</td>			</tr>			<tr>			<td align="left" valign="top" border="1">					Taxes</td><td>					<input type="text" style="40" name="taxes" value="'.$taxes.'">				</td>			</tr>			<tr>			<td align="left" valign="top" border="1">					Profit After Taxes</td><td>					<input type="text" style="40" name="afterTaxes" value="'.$profitAfterTaxes.'">				</td>			</tr>			<tr>			<td align="left" valign="top" border="1">					Other Income</td><td>					<input type="text" style="40" name="other" value="'.$otherIncome.'">				</td>			</tr>			<tr>			<td align="left" valign="top" border="1">					Net Income</td><td>					<input type="text" style="40" name="totalIncome" value="'.$totalIncome.'">				</td>			</tr>		   <tr>			  <td colspan="2" align="center" valign="top" border="1">				<input type="submit" name="submit" id="Submit" value="calculate" />			  </label></td>			  </tr>			</table></form>';	   //Calculate the gross profit: $gross = $totalRev - $vCost; echo "gross: ".$gross."<br />";  //Calculate the net profit: $netProfit = $gross - $overheadCost; echo "netProfit: ".$netProfit."<br />";  // Calculate Income after taxes: $afterTaxes = $netProfit - $taxes; echo "afterTaxes: ".$afterTaxes."<br />";  // Calculate the Total Income: $totalIncome = $afterTaxes + $otherIncome;  echo "totalIncome: ".$TotalIncome."<br />";

Link to comment
Share on other sites

This IS the code<?php//this is the top of your page, start of the scriptvar_dump($_POST);echo '<br/>';echo 'Revenue: ' . $_POST['revenue'] . '<br/>';echo '<br/>';echo 'Cost: ' . $_POST['cost'] . '<br/>'; // NAME STEP AND GIVE VALUE TO QUESTION VARIABLES SO ERROR CHECKING DOES NOT HAVE TO BE RECREATED FOR EVERY PAGE $stepNumber = '4i'; $numQuestions = '9'; //get values from the $_post array: $totalRev = $_POST['revenue']; echo "totalRev: ".$totalRev."<br />"; $vCost = $_POST['cost']; echo "vCost: ".$vCost."<br />"; $overheadCost = $_POST['overhead']; echo "overheadCost: ".$overheadCost."<br />"; $taxes = $_POST['taxes']; echo "taxes: ".$taxes."<br />"; $otherIncome = $_POST['other']; echo "other: ".$other."<br />"; //Calculate the gross profit: $gross = $totalRev - $vCost; echo "gross: ".$gross."<br />"; //Calculate the net profit: $netProfit = $gross - $overheadCost; echo "netProfit: ".$netProfit."<br />"; // Calculate Income after taxes: $afterTaxes = $netProfit - $taxes; echo "afterTaxes: ".$afterTaxes."<br />"; // Calculate the Total Income: $totalIncome = $afterTaxes + $otherIncome; echo "totalIncome: ".$totalIncome."<br />"; // Print out the results print ' <table border="1" cellpadding="4" cellspacing="3" width="350"> <tr> <td align="left" valign="top" border="1"> Total Revenue</td><td><input type="text" style="40" name="revenue" value="'.$totalRev.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Less: Variable Cost</td><td><input type="text" style="40" name="cost" value="'.$vCost.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Gross profit</td><td><input type="text" style="40" name="gross" value="'.$GrossProfit.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Less: Overhead Cost</td><td> <input type="text" style="40" name="overhead" value="'.$overheadCost.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Net Profit</td><td> <input type="text" style="40" name="netProfit" value="'.$netProfit.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Taxes</td><td> <input type="text" style="40" name="taxes" value="'.$taxes.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Profit After Taxes</td><td> <input type="text" style="40" name="afterTaxes" value="'.$profitAfterTaxes.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Other Income</td><td> <input type="text" style="40" name="other" value="'.$otherIncome.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Net Income</td><td> <input type="text" style="40" name="totalIncome" value="'.$totalIncome.'"> </td> </tr> <tr> <td colspan="2" align="center" valign="top" border="1"> <input type="submit" name="submit" id="Submit" value="calculate" /> </label></td> </tr> </table></form>';

Link to comment
Share on other sites

Check your variable names. You have several mismatched variables:Gross profit</td><td><input type="text" style="40" name="gross" value="'.$GrossProfit.'">...<input type="text" style="40" name="afterTaxes" value="'.$profitAfterTaxes.'">...
fixed those
Link to comment
Share on other sites

What's the current status? Is everything working like you expect?
No still not showing grossProfit, afterTaxes, totalIncome and total income still not calculating weird huh<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><style type="text/css">#tenForm form table tr td { text-align: center;}</style></head><body><p class="tenTitle">Module 4i: Profit / Loss Forecast<br /><?php//this is the top of your page, start of the scriptvar_dump($_POST);echo '<br/>';echo 'Revenue: ' . $_POST['revenue'] . '<br/>';echo '<br/>';echo 'Cost: ' . $_POST['cost'] . '<br/>'; // NAME STEP AND GIVE VALUE TO QUESTION VARIABLES SO ERROR CHECKING DOES NOT HAVE TO BE RECREATED FOR EVERY PAGE $stepNumber = '4i'; $numQuestions = '9'; //get values from the $_post array: $totalRev = $_POST['revenue']; echo "totalRev: ".$totalRev."<br />"; $vCost = $_POST['cost']; echo "vCost: ".$vCost."<br />"; $overheadCost = $_POST['overhead']; echo "overheadCost: ".$overheadCost."<br />"; $taxes = $_POST['taxes']; echo "taxes: ".$taxes."<br />"; $otherIncome = $_POST['other']; echo "other: ".$otherIncome."<br />"; //Calculate the gross profit: $grossProfit = $totalRev - $vCost; echo "grossProfit: ".$grossProfit."<br />"; //Calculate the net profit: $netProfit = $grossProfit - $overheadCost; echo "netProfit: ".$netProfit."<br />"; // Calculate Income after taxes: $afterTaxes = $netProfit - $taxes; echo "afterTaxes: ".$afterTaxes."<br />"; // Calculate the Total Income: $totalIncome = $afterTaxes + $otherIncome; echo "totalIncome: ".$totalIncome."<br />"; // Print out the results print ' <table border="1" cellpadding="4" cellspacing="3" width="350"> <tr> <td align="left" valign="top" border="1"> Total Revenue</td><td><input type="text" style="40" name="revenue" value="'.$totalRev.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Less: Variable Cost</td><td><input type="text" style="40" name="cost" value="'.$vCost.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Gross profit</td><td><input type="text" style="40" name="grossProfit" value="'.$grossProfit.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Less: Overhead Cost</td><td> <input type="text" style="40" name="overhead" value="'.$overheadCost.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Net Profit</td><td> <input type="text" style="40" name="netProfit" value="'.$netProfit.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Taxes</td><td> <input type="text" style="40" name="taxes" value="'.$taxes.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Profit After Taxes</td><td> <input type="text" style="40" name="afterTaxes" value="'.$afterTaxes.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Other Income</td><td> <input type="text" style="40" name="other" value="'.$otherIncome.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Net Income</td><td> <input type="text" style="40" name="totalIncome" value="'.$totalIncome.'"> </td> </tr> <tr> <td colspan="2" align="center" valign="top" border="1"> <input type="submit" name="submit" id="Submit" value="calculate" /> </label></td> </tr> </table></form>'; // DEFINE SESSION VARIABLES $_SESSION['email']=$_POST['email']; $_SESSION['emailCc']=$_POST['emailCc']; $_SESSION['name']=$_POST['name']; // DEFINE VARIABLES FOR MAILING TO USER AND BUZGATE $to = 'askbuz@buzgate.org,'.$_POST['email']; $email_subject = "Step ".$stepNumber." in Buzgate's Five Step Program"; for ($i = 1; $i <= $numQuestions; $i++) { $eBodyQuestions .= $questions[$i]."\n" .$_POST['data'.$i]."\n"; } $email_body = $eBodyQuestions; $headers = "From:".$_POST['email']; //PLACE VARIABLES IN MAIL FUNCTION mail($to, $email_subject, $email_body, $headers); // DEFINE VARIABLES FOR MAILING TO USER AND BUZGATE $toCc = $_POST['emailCc']; $email_subjectCc = "Step ".$stepNumber." in Buzgate's Five Step Program from ".$_POST['name']; $email_bodyCc = $_POST['name']." has sent this to you from www.BUZGate.org/8.0/".$state_abbrv_low."/".$page_name."\n Please contact us at askbuz@buzgate.org if you have received this in error.\n"; $email_bodyCc = $email_bodyCc.$eBodyQuestions; $headersCc = "From:askbuz@buzgate.org"; //PLACE VARIABLES IN CC MAIL FUNCTION mail($toCc, $email_subjectCc, $email_bodyCc, $headersCc); // DISPLAY RESPONSE TO CORRECTLY FILLING OUT FORM echo "<p class='textCenter'>Thank you ".$_POST['name']." for completing Step ".$stepNumber."</p> <p class='textCenter'><a href='five_steps_4summary.html'>Click here</a> to continue to 4Summary</p> <p class='textCenter'>Or <a href='five_steps_".$stepNumber.".html'>try this form again</a>.</p>"; ?>
Link to comment
Share on other sites

so we've confirmed that those values are showing up in var_dump after the form has submitted?
yes the only value not showing up is TotalIncome but i did notice thisarray(13) { ["revenue"]=> string(8) "20000.00" ["cost"]=> string(7) "4000.00" ["grossProfit"]=> string(0) "" ["overhead"]=> string(7) "1000.00" ["netProfit"]=> string(0) "" ["taxes"]=> string(1) "0" ["afterTaxes"]=> string(0) "" ["other"]=> string(6) "500.00" ["totalIncome"]=> string(0) "" ["submit"]=> string(9) "calculate" ["email"]=> string(0) "" ["emailCc"]=> string(0) "" ["name"]=> string(0) "" } Revenue: 20000.00where ever it is string(0) it does not show up in the form what does these numbers mean and why do they have zero in them do I need to a $_POST to make the others work but Net Profit did not need this. what am I missing
Link to comment
Share on other sites

the way to read this in pieces:

array(13)

says you have 13 members in the array

["revenue"]=> string(8) "20000.00"

tells you that member revenue is of type string which has 8 characters in it. (most languages treat strings like an array). This reading convention can be applied to all the other members, i.e. cost, overhead, etc.Now if one of those is coming over as an empty string, like:

["grossProfit"]=> string(0) ""

this means that $_POST has a member called grossProfit, but it doesn't have a value. Are you sure you input a value for these?

Link to comment
Share on other sites

do i need to have variable for Gross profit, After Taxes and Total Income
well, if its empty in var_dump, that means that's what the form is submitting. that's why we do var_dump at the beginning so we know the values of everything submitted before running off and doing calculations.
Link to comment
Share on other sites

well, if its empty in var_dump, that means that's what the form is submitting. that's why we do var_dump at the beginning so we know the values of everything submitted before running off and doing calculations.
But we did not need to do that for Net Profit it just has the same code as the others and it works?
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...