Jump to content

PHP Form calculating issue


JimKI

Recommended Posts

I have this php form below and I can't get it to calculate it returns a 0 in the net profit but nothing else help!!!!any help or points to how to do this will be helpful form is below.<p class="tenTitle"><p class="tenTitle">Module 4i: Profit / Loss Forecast<br /><?php // 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']; $vCost = $_post['cost']; $overheadCost = $_post['overhead']; $taxes = $_post['taxes']; $otherIncome = $_post['other']; //Calculate the gross profit: $gross = $totalRev - $vCost; //Calculate the net profit: $netProfit = $gross - $overheadCost; // Calculate Income after taxes: $afterTaxes = $netProfit - $taxes; // Calculate the Total Income: $totalIncome = $afterTaxes + $otherIncome; // Print out the resultsprint ' <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="totalRev" value="'.$totalRev.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Less: Variable Cost</td><td><input type="text" style="40" name="vCost" value="'.$vCost.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Gross profit</td><td><input type="text" style="40" name="vCost" value="'.$GrossProfit.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Less: Overhead Cost</td><td> <input type="text" style="40" name="vCost" value="'.$overheadCost.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Net Profit</td><td> <input type="text" style="40" name="vCost" 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="profitAfterTaxes" value="'.$profitAfterTaxes.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Other Income</td><td> <input type="text" style="40" name="otherIncome" value="'.$otherIncome.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Net Income</td><td> <input type="text" style="40" name="netIncome" value="'.$netIncome.'"> </td> </tr> <tr> <td colspan="2" align="left" 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

* $_post should be $_POST* you should echo at each step of the calc process to make sure the values you are getting/calculating are what you expect them to be

Link to comment
Share on other sites

* $_post should be $_POST* you should echo at each step of the calc process to make sure the values you are getting/calculating are what you expect them to be
there has to be more wrong because i fixed the post to capital p and still not working?where do i put the echo since i already have print?
Link to comment
Share on other sites

there has to be more wrong because i fixed the post to capital p and still not working?where do i put the echo since i already have print?
* $_POST. the whole things needs to be capitalized, just like at the end of your script* I would say each time you do a calculation, or after an assignment from the $_POST array. Often times it's helpful to do a var_dump on $_POST at the beginning of the script to get a good overview/summary of all the value(s) being passed over.
Link to comment
Share on other sites

* $_POST. the whole things needs to be capitalized, just like at the end of your script* I would say each time you do a calculation, or after an assignment from the $_POST array. Often times it's helpful to do a var_dump on $_POST at the beginning of the script to get a good overview/summary of all the value(s) being passed over.
I sthere a better way to do this i've taken a long time to do this for my boss and need a quicker resolution to the problem?
Link to comment
Share on other sites

I sthere a better way to do this i've taken a long time to do this for my boss and need a quicker resolution to the problem?
One must find the problem before one finds the solution.scientist is trying to help you find the problem. We can't know what data is coming into your script or what it's supposed to be. Only you can know that. You have to know what your variables are and whether they are what they should be. You do that by echoing them out throughout your script.So, to figure out what your variables are echo them out anytime you assign a value from $_POST or perform a calculation:
//get values from the $_post array:$totalRev = $_POST['revenue'];echo "totRev: ".$totalRev."<br />";$vCost = $_POST['cost'];echo "vCost: ".$vCost."<br />";...//Calculate the gross profit:$gross = $totalRev - $vCost;echo "gross: ".$gross."<br />";//Calculate the net profit:$netProfit = $gross - $overheadCost;echo "netProfit: ".$netProfit."<br />";....

Link to comment
Share on other sites

One must find the problem before one finds the solution.scientist is trying to help you find the problem. We can't know what data is coming into your script or what it's supposed to be. Only you can know that. You have to know what your variables are and whether they are what they should be. You do that by echoing them out throughout your script.So, to figure out what your variables are echo them out anytime you assign a value from $_POST or perform a calculation:
//get values from the $_post array: $totalRev = $_POST['revenue']; echo "totRev: ".$totalRev."<br />"; $vCost = $_POST['cost']; echo "vCost: ".$vCost."<br />"; ... //Calculate the gross profit: $gross = $totalRev - $vCost; echo "gross: ".$gross."<br />";  //Calculate the net profit: $netProfit = $gross - $overheadCost; echo "netProfit: ".$netProfit."<br />"; ....

okay thank you, Now I have this and it still in not calculating anything are the values correct. I will also attach my html page that goes along with this maybe i have something wrong in there? not sure why it does not work.<p class="tenTitle"><p class="tenTitle">Module 4i: Profit / Loss Forecast<br /><?php // 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="totalRev" value="'.$totalRev.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Less: Variable Cost</td><td><input type="text" style="40" name="vCost" 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="profitAfterTaxes" value="'.$profitAfterTaxes.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Other Income</td><td> <input type="text" style="40" name="otherIncome" value="'.$otherIncome.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Net Income</td><td> <input type="text" style="40" name="netIncome" value="'.$netIncome.'"> </td> </tr> <tr> <td colspan="2" align="left" 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>"; ?>HTML<!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 /><div id="tenForm"> What are your financial estimates for the first 12 months of operation including expenses, income, profit, taxes, income after taxes, and other money income from sources other than business (i.e., Social Security, spouse's wages, retirement pensions, etc.)<p>In forecasting your businesses potential, it is critical to distinguish between what you hope will happen, and what you expect will happen. We are usually quite optimistic when we think about our businesses potential, and are reluctant to accept that this is the "best of all possible worlds" expectation and reality may be considerable lower. It is very important to be as realistic as possible in developing these expectations or forecasts of your businesses potential, because you are making important decisions about the investment of your own time and money. Others such as family members may be involved as well. In Step 3, you completed a series of exercises that allowed you to develop a <a href="http://www.buzgate.org/8.0/excel/forecasting_wrksht.xls" target="_blank">12 month forecast</a>. Now is a good time to review those results and think again about whether or not the assumptions are realistic, and the results make sense. Your Accounting professional wiil need to help you estimateyour taxes otherwise enter 0(zero). For other money income; list income from any other sources such as social security, spouses wages, etc. This also is a good time to discuss these results with your counselor or mentor. Once again, the process of discussing these ideas helps to see whether or not they make sense.</p> <form action="five4i.php" method="POST" > <table width="350" border="1" align="center" cellpadding="4" cellspacing="3"> <tr> <td align="center" valign="top" border="1"> Total Revenue</td><td><input type="text" style="40" name="totalRev" value=""> </td> </tr> <tr align="left"> <td align="center" valign="top" border="1"> Less: Variable Cost</td><td><input type="text" style="40" name="vCost" value=""> </td> <tr> <td align="center" valign="top" border="1"> Gross profit</td><td><input type="text" style="40" name="grossProfit" value=""> </td> <tr> <td align="center" valign="top" border="1"> Less: Overhead Cost</td><td> <input type="text" style="40" name="overhead" value=""> </td> </tr> <tr> <td align="center" valign="top" border="1"> Net Profit</td><td> <input type="text" style="40" name="netProfit" value=""> </td> </tr> <tr> <td align="center" valign="top" border="1"> Taxes</td><td> <input type="text" style="40" name="taxes" value=""> </td> </tr> <tr> <td align="center" valign="top" border="1"> Profit After Taxes</td><td> <input type="text" style="40" name="profitAfterTaxes" value=""> </td> </tr> <tr> <td align="center" valign="top" border="1"> Other Income</td><td> <input type="text" style="40" name="otherIncome" value=""> </td> </tr> <tr> <td align="left" valign="top" border="1"> Net Income</td><td> <input type="text" style="40" name="netIncome" value=""> </td> </tr> <tr> <td colspan="2" align="left" valign="top" border="1"> <input type="submit" name="submit" id="Submit" value="Calculate" /> </label></td> </tr> </table> <table border="0" align="center" cellpadding="3" cellspacing="2"> <tr> <td valign="top" border="0"> Submitting the form (* = required) </th> </tr> <tr> <td class="submitCell"> '.$emailSpan.'<br /> (to receive a copy of this form)<br /> <input type="text" size="40" maxlength="100" name="email" value="" /> </td> </tr> <tr> <td class="submitCell"> Send Copy To eMentor<br /> <input type="text" size="40" maxlength="100" name="emailCc" value="" /> </td> </tr> <tr> <td class="submitCell"> '.$nameSpan.'<br /> (*required if sending a copy)<br /> <input type="text" size="40" maxlength="100" name="name" value="" /> </td> </tr> <tr> <td align="center" class="submitCell"> <input type="reset" value="Clear" /> <input type="submit" name="submit" value="Submit" /><br /> <a href="'.$filePathState.'about_privacy.html" target="_blank"><span style="font-size:9px;">View our privacy policy</span></a> </td> </tr></table></form></div></body></html>
Link to comment
Share on other sites

I have this form and it is not calculating anything are the values correct. I will also attach my html page that goes along with this maybe i have something wrong in there? not sure why it does not work.<p class="tenTitle"><p class="tenTitle">Module 4i: Profit / Loss Forecast<br /><?php // 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="totalRev" value="'.$totalRev.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Less: Variable Cost</td><td><input type="text" style="40" name="vCost" 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="profitAfterTaxes" value="'.$profitAfterTaxes.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Other Income</td><td> <input type="text" style="40" name="otherIncome" value="'.$otherIncome.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Net Income</td><td> <input type="text" style="40" name="netIncome" value="'.$netIncome.'"> </td> </tr> <tr> <td colspan="2" align="left" 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>"; ?>HTML<!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 /><div id="tenForm"> What are your financial estimates for the first 12 months of operation including expenses, income, profit, taxes, income after taxes, and other money income from sources other than business (i.e., Social Security, spouse's wages, retirement pensions, etc.)<p>In forecasting your businesses potential, it is critical to distinguish between what you hope will happen, and what you expect will happen. We are usually quite optimistic when we think about our businesses potential, and are reluctant to accept that this is the "best of all possible worlds" expectation and reality may be considerable lower. It is very important to be as realistic as possible in developing these expectations or forecasts of your businesses potential, because you are making important decisions about the investment of your own time and money. Others such as family members may be involved as well. In Step 3, you completed a series of exercises that allowed you to develop a <a href="http://www.buzgate.org/8.0/excel/forecasting_wrksht.xls" target="_blank">12 month forecast</a>. Now is a good time to review those results and think again about whether or not the assumptions are realistic, and the results make sense. Your Accounting professional wiil need to help you estimateyour taxes otherwise enter 0(zero). For other money income; list income from any other sources such as social security, spouses wages, etc. This also is a good time to discuss these results with your counselor or mentor. Once again, the process of discussing these ideas helps to see whether or not they make sense.</p> <form action="five4i.php" method="POST" > <table width="350" border="1" align="center" cellpadding="4" cellspacing="3"> <tr> <td align="center" valign="top" border="1"> Total Revenue</td><td><input type="text" style="40" name="totalRev" value=""> </td> </tr> <tr align="left"> <td align="center" valign="top" border="1"> Less: Variable Cost</td><td><input type="text" style="40" name="vCost" value=""> </td> <tr> <td align="center" valign="top" border="1"> Gross profit</td><td><input type="text" style="40" name="grossProfit" value=""> </td> <tr> <td align="center" valign="top" border="1"> Less: Overhead Cost</td><td> <input type="text" style="40" name="overhead" value=""> </td> </tr> <tr> <td align="center" valign="top" border="1"> Net Profit</td><td> <input type="text" style="40" name="netProfit" value=""> </td> </tr> <tr> <td align="center" valign="top" border="1"> Taxes</td><td> <input type="text" style="40" name="taxes" value=""> </td> </tr> <tr> <td align="center" valign="top" border="1"> Profit After Taxes</td><td> <input type="text" style="40" name="profitAfterTaxes" value=""> </td> </tr> <tr> <td align="center" valign="top" border="1"> Other Income</td><td> <input type="text" style="40" name="otherIncome" value=""> </td> </tr> <tr> <td align="left" valign="top" border="1"> Net Income</td><td> <input type="text" style="40" name="netIncome" value=""> </td> </tr> <tr> <td colspan="2" align="left" valign="top" border="1"> <input type="submit" name="submit" id="Submit" value="Calculate" /> </label></td> </tr> </table> <table border="0" align="center" cellpadding="3" cellspacing="2"> <tr> <td valign="top" border="0"> Submitting the form (* = required) </th> </tr> <tr> <td class="submitCell"> '.$emailSpan.'<br /> (to receive a copy of this form)<br /> <input type="text" size="40" maxlength="100" name="email" value="" /> </td> </tr> <tr> <td class="submitCell"> Send Copy To eMentor<br /> <input type="text" size="40" maxlength="100" name="emailCc" value="" /> </td> </tr> <tr> <td class="submitCell"> '.$nameSpan.'<br /> (*required if sending a copy)<br /> <input type="text" size="40" maxlength="100" name="name" value="" /> </td> </tr> <tr> <td align="center" class="submitCell"> <input type="reset" value="Clear" /> <input type="submit" name="submit" value="Submit" /><br /> <a href="'.$filePathState.'about_privacy.html" target="_blank"><span style="font-size:9px;">View our privacy policy</span></a> </td> </tr></table></form></div></body></html>

Link to comment
Share on other sites

er... people have already been kind enough to help you in this thread that you have already started here about this exact same issue:http://w3schools.invisionzone.com/index.ph...mp;#entry189767please don't double post, it will only divert attention from help getting to you as effeciently as possible. Hopefully a moderator will just merge this with your other thread.

Link to comment
Share on other sites

I sthere a better way to do this i've taken a long time to do this for my boss and need a quicker resolution to the problem?
well, don't you want to know what your script is doing? Since it's not doing what you are expecting it do, the only way to follow the logic is to actively participate in it. Now you are saying that it is isn't calculating. Have you confirmed that all the values are coming over? Have you tried the calculations on your own to see where there might be a problem? The whole point of the echo's is so that you can trace down the steps that your script is going through to indeed determine that it is doing what you want it to do. There's no way around that, professional developers do it all the time.As I think you need to be more specific in your request for help, the echo statements should at least be able to help you help us determine where in the process things are going wrong, and then we can focus on specific issues as they present themselves. so first things first, are all the $_POST variables coming over? Can you echo/print lines stating comments about the app's logic? For instance, "calculating total...", "total is: " . $total; etc.
Link to comment
Share on other sites

What specifically isn't calculating? Also, where is it in your script?
it needs to calculate the gross profit, Net profit, income after taxes, and total income. you insert amounts in total revenue and variable cost as well as overhead costs taxes otherincome and the hit calculate and it should give you gross profit, net profit, income after taxes and total income it should also return form with these amounts in it.
Link to comment
Share on other sites

the echo statements should at least be able to help you help us determine where in the process things are going wrong, and then we can focus on specific issues as they present themselves. so first things first, are all the $_POST variables coming over? Can you echo/print lines stating comments about the app's logic? For instance, "calculating total...", "total is: " . $total; etc.
Exactly. Are your echo statements printing out the correct values for totRevenue, vCost, etc? Are the calculations (gross, netProfit, etc.) printing the correct values?Since there are no if/else or other logic structures in your code printing out the program's logic will not help in this situation, but if there were logic structures then yes, you'd definitely need to print out pointers and statements that tell what path the script is taking.If your variables are not correct you need to look at why. Tell us which ones are wrong. What are their values? What are they supposed to be?
Link to comment
Share on other sites

Exactly. Are your echo statements printing out the correct values for totRevenue, vCost, etc? Are the calculations (gross, netProfit, etc.) printing the correct values?Since there are no if/else or other logic structures in your code printing out the program's logic will not help in this situation, but if there were logic structures then yes, you'd definitely need to print out pointers and statements that tell what path the script is taking.If your variables are not correct you need to look at why. Tell us which ones are wrong. What are their values? What are they supposed to be?
I tried to put in values in the form and it excepts them it just doesn't take the values and subtract or add when needed depending on if you are trying to find Gross profit , Net Profit, Income after taxes, or total income.the values are inputted by a user of the form so I don't know the values.
Link to comment
Share on other sites

I tried to put in values in the form and it excepts them it just doesn't take the values and subtract or add when needed depending on if you are trying to find Gross profit , Net Profit, Income after taxes, or total income.the values are inputted by a user of the form so I don't know the values.
This is what we have been trying to tell you. The first thing you should be doing to help yourself is to display ALL the submitted values from the form, to make sure that calculation are even possible. Is this even happening? You added the echo's in before, but never confirmed if you were even seeing the data. The echo's weren't suggested for presentation, it's a debugging tool.
echo $_POST['submitted_value1'];echo $_POST['submitted_value2'];//etc

Link to comment
Share on other sites

This is what we have been trying to tell you. The first thing you should be doing to help yourself is to display ALL the submitted values from the form, to make sure that calculation are even possible. Is this even happening? You added the echo's in before, but never confirmed if you were even seeing the data. The echo's weren't suggested for presentation, it's a debugging tool.
echo $_POST['submitted_value1']; echo $_POST['submitted_value2']; //etc

Sorry newbie here not sure i understand I have a form i input numbers into Total revenue text box then input numbers into Variable costs, then input numbers into taxes, then input numbers into other Income and then I hit calculate. when i do that it returns the form but with only 0 in the net Profit?
Link to comment
Share on other sites

when i do that it returns the form but with only 0 in the net Profit?
Well, why does it do that? It looks like you're trying to get some values from $_POST. Have you verified that the values you're getting from $_POST are the same values you entered in the fields, and that nothing is left out? That's step #1 in debugging things like this, it's what everyone in the thread has been trying to get you to do, and what you apparently haven't done yet. We're still stuck on step 1. We can't move on to step 2 until this has been completed. You must verify the values in your variables before any other troubleshooting can take place. You've re-stated the same problem several times, but you haven't verified that the PHP script is actually receiving the correct values that were submitted from the form.
Link to comment
Share on other sites

Sorry newbie here not sure i understand I have a form i input numbers into Total revenue text box then input numbers into Variable costs, then input numbers into taxes, then input numbers into other Income and then I hit calculate. when i do that it returns the form but with only 0 in the net Profit?
right. at the beginning of the page, within the script tags, you are performing calculations using members from the $_POST array. You've also echo'd parts of this process. Does that not show anything? What I am saying is before you do any of that, check those values to begin with. The easiest way to do that is with var_dump, (although harder to read), but then you can echo them individually as well.
<? 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/>';//etc..rest of your code?>

the point is to see if the values are even being submitted at all. This is the most critical step of the whole process, naturally. Also, you should verify you are accessing the correct members. In your example you are doing this:

$totalRev = $_POST['revenue'];echo "totalRev: ".$totalRev."<br />";

but in your form, I don't see a form field named 'revenue'. I see one named totalRev.....

Link to comment
Share on other sites

Well, why does it do that? It looks like you're trying to get some values from $_POST. Have you verified that the values you're getting from $_POST are the same values you entered in the fields, and that nothing is left out? That's step #1 in debugging things like this, it's what everyone in the thread has been trying to get you to do, and what you apparently haven't done yet. We're still stuck on step 1. We can't move on to step 2 until this has been completed. You must verify the values in your variables before any other troubleshooting can take place. You've re-stated the same problem several times, but you haven't verified that the PHP script is actually receiving the correct values that were submitted from the form.
It does it because the code is probably wrong and I don't know PHP enough to figure it out there are no books on calculating with PHP they all are general I learn by seeing all the book give you is general info and since know one out there has had to make these particular calculations i have nothing to look at to try to figure out.I know I can input numbers but then it all goes wrong since when i hit calculate it returns form table with only 0 in Net Profit.
Link to comment
Share on other sites

right. at the beginning of the page, within the script tags, you are performing calculations using members from the $_POST array. You've also echo'd parts of this process. Does that not show anything? What I am saying is before you do any of that, check those values to begin with. The easiest way to do that is with var_dump, (although harder to read), but then you can echo them individually as well.
<? php //this is the top of your page, start of the script var_dump($_POST); echo '<br/>'; echo 'Revenue: ' . $_POST['revenue'] . '<br/>'; echo '<br/>'; echo 'Cost: ' . $_POST['cost'] . '<br/>'; //etc . . rest of your code ?>

the point is to see if the values are even being submitted at all. This is the most critical step of the whole process, naturally. Also, you should verify you are accessing the correct members. In your example you are doing this:

$totalRev = $_POST['revenue']; echo "totalRev: ".$totalRev."<br />";

but in your form, I don't see a form field named 'revenue'. I see one named totalRev.....

So what you are telling me is in need this first var_dump($_POST); then I also have the wrong names the names should be what is inside here correct. $_POST['revenue'];so the second part makes sense that i named the table input names wrong. thanks
Link to comment
Share on other sites

It does it because the code is probably wrong and I don't know PHP enough to figure it out there are no books on calculating with PHP they all are general I learn by seeing all the book give you is general info and since know one out there has had to make these particular calculations i have nothing to look at to try to figure out.I know I can input numbers but then it all goes wrong since when i hit calculate it returns form table with only 0 in Net Profit.
well, everyone's application is always going to be specific in nature, so its only beneficial for books to show you syntax, conventions, and examples. Why not start small then, and build up your skills. The most fundamental part of this process is getting a basic form to submit to a php script and then generate some output based on that input, right? Try small, and then add more and more pieces of functionality in. The w3schools tutorials should have even to get you going on that alone, (which is almost everything you need). http://www.w3schools.com/php/php_forms.asp
Link to comment
Share on other sites

So what you are telling me is in need this first var_dump($_POST); then I also have the wrong names the names should be what is inside here correct. $_POST['revenue'];so the second part makes sense that i named the table input names wrong. thanks
i'm not sure you get it. Please see my newest post about how to learn this stuff. When you submit the form (not a table) and its inputs, the name of each input becomes a member in the $_POST/$_GET array (depending on the form's method). The form defines the members of the array, and you define them. The names you assign to the form inputs are what you should be checking for in the PHP script in the $_POST array.var_dump($var) will show you lots of information relative to what's in the parenthesis. (type, length, value, etc) It's another useful debugging tool.
Link to comment
Share on other sites

i'm not sure you get it. Please see my newest post about how to learn this stuff. When you submit the form (not a table) and its inputs, the name of each input becomes a member in the $_POST/$_GET array (depending on the form's method). The form defines the members of the array, and you define them. The names you assign to the form inputs are what you should be checking for in the PHP script in the $_POST array.var_dump($var) will show you lots of information relative to what's in the parenthesis. (type, length, value, etc) It's another useful debugging tool.
Okay I did the var dump I see now what you are talking about and I have fixed some things but still have a few things that are not going in the form and not sure why since the the net income is calculated and it goes in the form everything else is calculating but not going in the form Gross, After Taxes, Net income is not adding and not going in form. this is the results.Module 4i: Profit / Loss Forecast array(13) { ["revenue"]=> string(8) "20000.00" ["cost"]=> string(7) "4000.00" ["gross"]=> string(0) "" ["overhead"]=> string(7) "1000.00" ["netProfit"]=> string(0) "" ["taxes"]=> string(2) "10" ["afterTaxes"]=> string(0) "" ["other"]=> string(6) "500.00" ["netIncome"]=> string(0) "" ["submit"]=> string(9) "Calculate" ["email"]=> string(0) "" ["emailCc"]=> string(0) "" ["name"]=> string(0) "" } Revenue: 20000.00Cost: 4000.00totalRev: 20000.00vCost: 4000.00overheadCost: 1000.00taxes: 10other: 500.00gross: 16000netProfit: 15000afterTaxes: 14990totalIncome: Total Revenue Less: Variable Cost Gross profit Less: Overhead Cost Net Profit Taxes Profit After Taxes Other Income Net Income
Link to comment
Share on other sites

I'm not sure why this is so difficult. Let me try to explain with an analogy:

Your task is to remove a Phillips screw. You're sitting there looking at the screw. You grab a screwdriver, still staring at the screw, you put the head of the screwdriver to the screw and turn left, and nothing happens.So, you ask "why isn't the screwdriver removing the screw?"The response is "are you sure it's a Phillips screwdriver and not a flathead?"You say "Thanks. I try to remove the screw, but it won't turn.""Look at the screwdriver. Is it a Phillips?""Thanks, but I'm still not able to turn it."
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
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...