0
Salary Calculator.php

<html>
<body>

<form name="SalarySaver" method="POST" action="SalarySaverModel.php">
<table>
<tr>
    <td>Period : </td>
    <td><input type="text" name="SYear" id="SYear"/></td>
    <td><select name="SMonth" id="SMonth">
            <option value="January">January</option>
            <option value="February">February</option>
            <option value="March">March</option>
            <option value="April">April</option>
            <option value="May">May</option>
            <option value="June">June</option>
            <option value="July">July</option>
            <option value="August">August</option>
            <option value="September">September</option>
            <option value="October">October</option>
            <option value="November">November</option>
            <option value="December">December</option>
        </select>
    </td>
</tr>
</table>

  <table border="1">
    <tr> 
      <td rowspan="2">Employee Name</td>
      <td rowspan="2">Days</td>
      <td rowspan="2">Wages</td>
      <td rowspan="2">Kg's</td>
      <td rowspan="2">Kg's/Days</td>
      <td rowspan="2">Extra Kg's</td>
      <td rowspan="2">Wage for Extra Kg's</td>
      <td rowspan="2">Total Wages</td>
      <td colspan="3">EPF/ETF</td>
      <td rowspan="2">Advances</td>
      <td rowspan="2">Festival Advances</td>
      <td rowspan="2">Balance Wages</td>
    </tr>
    <tr> 
      <td>8%</td>
      <td>12%</td>
      <td>3%</td>
    </tr>
    <?php include 'SalaryCalculatorModel.php'; ?>
  </table>
  <input name="Save" type="submit" value="Save"><a href="ScrapCalculator.php" target="_self">Scrap Calculator</a>
</form>

</body>
</html>


SalaryCalculatorModel.php

<?php 

include 'dbconnection.php'; 

 $Days=0; $Kg=0.00; $Wage=0.00; 
 $Rate=0.00;  $KgDivDays=0.00; $ExtraKgs = 0.00;
 $WageExtraKgs=0.00; $TotalWages=0.00;
 $BalanceWage=0.00; $EightPerc=0.00; $TwelvePerc=0.00; $ThreePerc=0.00;
 $Advances=0.00; $FestAdvances=0.00;

//execute the SQL query and return records
$result = mysql_query("SELECT EmployeeName,DailyRate FROM employees");


//fetch the data from the database 
$i = 0;
while ($row = mysql_fetch_array($result)) {
    echo "<tr><td>".$row{'EmployeeName'}."</td>";
    $Rate=$row{'DailyRate'};
    //echo "<td>".$Rate."</td>";
    //echo "<td style = 'display:none'>".$row{'DailyRate'}."</td>";
    //echo $Rate;
    echo "<td><input type='text' name='Days' id='Days".$i."' onChange='CalcWage(".$i.",".$Rate.");'/></td>";
    echo "<td id='Wage".$i."'>".$Wage."</td>";
    echo "<td><input type='text' name='Kg' id='Kg".$i."' onChange='CalcAmount(".$i.",".$Rate.");'/></td>";
    echo "<td id='KgDivDays".$i."'>".$KgDivDays."</td>";
    echo "<td id='ExtraKgs".$i."'>".$ExtraKgs."</td>";
    echo "<td id='WageExtraKgs".$i."'>".$WageExtraKgs."</td>";
    echo "<td id='TotalWages".$i."'>".$TotalWages."</td>";
    echo "<td id='EightPerc".$i."'>".$EightPerc."</td>";
    echo "<td id='TwelvePerc".$i."'>".$TwelvePerc."</td>";
    echo "<td id='ThreePerc".$i."'>".$ThreePerc."</td>";
    echo "<td><input type='text' name='Advances' id='Advances".$i."'/></td>";
    echo "<td><input type='text' name='FestAdvances' id='FestAdvances".$i."' onChange='CalcBalanceWage(".$i.",".$Rate.");'/></td>";
    echo "<td id='BalanceWage".$i."'>".$BalanceWage."</td>";
    $i++;
}

?>

<script type="text/javascript">

function CalcWage(i,php_rate){
    var Days=document.getElementById('Days'+i).value;
    //var php_rate = "<?php echo $Rate; ?>";
    //alert(php_rate);
    var Wage=parseFloat(Days*php_rate);
    document.getElementById('Wage'+i).innerHTML= Wage;
    return Wage;
}

function CalcAmount(i,php_rate){
    var Kg=document.getElementById('Kg'+i).value;
    var Days=document.getElementById('Days'+i).value;
    var KgDivDays = parseFloat(Days*4);
    document.getElementById('KgDivDays'+i).innerHTML= KgDivDays;
    var ExtraKgs=Kg-KgDivDays;
    document.getElementById('ExtraKgs'+i).innerHTML= ExtraKgs;
    var WageExtraKgs=ExtraKgs*50;
    document.getElementById('WageExtraKgs'+i).innerHTML= WageExtraKgs;
    var BasicSal = CalcWage(i,php_rate);
    var TotalWages= BasicSal + WageExtraKgs;
    document.getElementById('TotalWages'+i).innerHTML= TotalWages;
    var EightPerc= parseFloat(BasicSal * 0.08);
    document.getElementById('EightPerc'+i).innerHTML= EightPerc;
    var TwelvePerc= parseFloat(BasicSal * 0.12);
    document.getElementById('TwelvePerc'+i).innerHTML= TwelvePerc;
    var ThreePerc= parseFloat(BasicSal * 0.03);
    document.getElementById('ThreePerc'+i).innerHTML= ThreePerc;
    return TotalWages;
}

function CalcBalanceWage(i,php_rate){
    var Advances=parseFloat(document.getElementById('Advances'+i).value);
    var FestAdvances=parseFloat(document.getElementById('FestAdvances'+i).value);
    var TotWage = CalcAmount(i,php_rate); 
    var BasSal =  CalcWage(i,php_rate); 
    var Deductions = parseFloat(Advances+FestAdvances+(BasSal*0.08));
    var BalanceWage=parseFloat(TotWage-Deductions);
    document.getElementById('BalanceWage'+i).innerHTML= BalanceWage;
    return BalanceWage;
}

</script>

<?php
//close the connection
mysql_close($dbhandle);
?>

上面的 SalaryCalculatorModel.php 代码生成并填充 SalaryCalculator.php 上的列。

我想使用 SalarySaver.php 保存呈现页面上的所有信息(在我输入/计算之后)值

我的问题是我在 Salary Calculator.php 上有表单字段以及从 SalaryCalculatorModel.php 填写的列。如何将动态 html 表上的值保存到 mysql 数据库表中?

4

1 回答 1

0

I don't know if i understand the question. You want to insert data from this table into a mysql db table? If so you should have

<form method="POST" action="page_where_inserting_in_mysql">
    ...
</form>

And into the new page you should have

mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("db_name") or die(mysql_error());
mysql_query("INSERT INTO table_name (field1, field2, ...) VALUES('".$_POST['value1']."', '".$_POST['value2']."',... ) ") or die(mysql_error()); 

Hope it helps. If you meant something else with you're question, please tell me. I'll help you if I can.

于 2013-06-28T11:16:59.407 回答