2013-06-28 70 views
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上的列。將某些輸入字段的動態生成的表保存到mysql表中

我想保存所呈現的所有頁面上的信息(後我進入/計算)使用SalarySaver.php

這個問題我已經是我填的薪酬形式Calculator.php中領域以及列中的值從SalaryCalculatorModel.php中取出。如何將動態html表中的值保存到mysql數據庫表中?

回答

0

我不知道我是否理解這個問題。你想從這個表中插入數據到一個MySQL數據庫表? 如果是這樣你應該有

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

而進入新的頁面,你應該有

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

希望它能幫助。如果你的意思是其他問題,請告訴我。如果可以的話,我會幫你的。

相關問題