Dan560
asked on
PHP using data from table.
Hi,
I have a PHP script that calculates an employees potential bonus, based on the figures that are entered in my html form.
The form is used to calculate an employees bonus. The form asks the following questions.
Market
What is your salary
What is review score
What is the customer satisfaction score
However to get their potential bonus the company profits figure needs to be pulled from my mysql table. This figure is not entered by the user however it is inserted using another PHP form used by their managers. This form works well.
So my calculation would look like
Salary * review * customer satisfaction * profit factors
My table for the company profits looks like this
Market Profit_Factor
UK 50
BE 200
FR 40
My first question is how can I include the profit factor figure into my calculation.
My second question is how can I tell PHP to use the profit factor that matches the market selected in my form.
I have a PHP script that calculates an employees potential bonus, based on the figures that are entered in my html form.
The form is used to calculate an employees bonus. The form asks the following questions.
Market
What is your salary
What is review score
What is the customer satisfaction score
However to get their potential bonus the company profits figure needs to be pulled from my mysql table. This figure is not entered by the user however it is inserted using another PHP form used by their managers. This form works well.
So my calculation would look like
Salary * review * customer satisfaction * profit factors
My table for the company profits looks like this
Market Profit_Factor
UK 50
BE 200
FR 40
My first question is how can I include the profit factor figure into my calculation.
My second question is how can I tell PHP to use the profit factor that matches the market selected in my form.
<html>
<body>
<center>
<h2> ADD TWO NUMBERS! </h2>
<form action="addition.php" method="post">
<CENTER><input type="text" name="salary_factor" id="salary_factor" /></center>
<td><select id="personal_factor" name='personal_factor'
<option value="None">Please Select Value</option>
<option value="135">Outstanding Review</option>
<option value="120">Excellent</option>
<option value="100">Good</option>
<option value="75">Satisfactory</option>
<option value="0">Unsatifactory</option>
</select></td>
<td><select id="customer_factor" name='customer_factor'
<option value="None">Please Select Value</option>
<option value="115">90%</option>
<option value="75">80%</option>
<option value="50">>70%</option>
<option value="0"><=60%</option>
</select></td>
=
<T><input type="submit" value="Answer is ->>" />
</form>
<?php
$personal_factor = $_POST["personal_factor"];
$customer_factor = $_POST["customer_factor"];
$salary_factor = $_POST["salary_factor"];
$answer = $personal_factor * $customer_factor * $salary_factor;
echo $answer;
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok I've managed to solve it.
The first error I posted was because I could not connect to the DB I used the following code to help me debug that -
$result = mysql_query($sql, $db) or die (mysql_error());
secondly I got an error stating Undefined index on line 21
I had to change
mysql_fetch_row.
to mysql_fetch_assoc
source: http://stackoverflow.com/questions/7895862/mysql-undefined-indexes-even-though-they-have-been-defined
Hopefully that info will be useful to someone.
However thanks for your help as it definitely set me on the right path.
The first error I posted was because I could not connect to the DB I used the following code to help me debug that -
$result = mysql_query($sql, $db) or die (mysql_error());
secondly I got an error stating Undefined index on line 21
I had to change
mysql_fetch_row.
to mysql_fetch_assoc
source: http://stackoverflow.com/questions/7895862/mysql-undefined-indexes-even-though-they-have-been-defined
Hopefully that info will be useful to someone.
However thanks for your help as it definitely set me on the right path.
ASKER
However I get the following error messages..
Notice: Undefined variable: db in C:\xampp\htdocs\boncalc\ad
Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\boncalc\ad
Warning: mysql_fetch_row() expects parameter 1 to be resource, null given in C:\xampp\htdocs\boncalc\ad
0
Thanks in advance for your help.
Open in new window