【发布时间】:2017-09-29 15:09:26
【问题描述】:
任何人都可以帮助我获得基本工资和津贴的增加,并将其插入到总日薪中,而无需单击按钮。这是我的 php 代码。
这是我的 UI 的 Screen Shot。
代码:
<?php
$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("laboursalary", $connection);
if(isset($_POST['submit'])){
$ID = $_POST['ID'];
$Name = $_POST['Name'];
$Location = $_POST['Location'];
$Category = $_POST['Category'];
$LabourSupplier = $_POST['LabourSupplier'];
$Home = $_POST['Home'];
$Mobile = $_POST['Mobile'];
$BasicSalary = $_POST['BasicSalary'];
$Allowance1 = $_POST['Allowance1'];
$Allowance2 = $_POST['Allowance2'];
$DayRate = $_POST['$DayRate'];
$OTrate = $_POST['OTrate'];
if($ID !=''||$Name !=''){
$query = mysql_query("insert into attendance(ID, Name, Location, Category,LabourSupplier,Home,Mobile,BasicSalary,Allowance1,Allowance2,DayRate,OTrate) values ('$ID','$Name','$Location','$Category','$LabourSupplier','$Home','$Mobile','$BasicSalary','$Allowance1','$Allowance2','$DayRate','$OTrate')");
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}
else{
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}
mysql_close($connection);
?>
在我输入基本工资和津贴 1 的值后,我想自动将这两个加到 Day Rate 中。
这是我的 HTML 代码。
<form id="details" action="" method="POST">
<fieldset> ID:
<input class="input" type="text" name="ID" value="" />
</fieldset>
<fieldset> Name:
<input class="input" type="text" name="Name" value="" />
</fieldset>
<fieldset> Location:
<input class="input" type="text" name="Location" value="" />
</fieldset>
<fieldset> Category:
<input class="input" type="text" name="Category" value="" />
</fieldset>
<fieldset> Labour Supplier:
<input class="input" type="text" name="LabourSupplier" value="" />
</fieldset>
<fieldset> Telephone:
<input class="input" type="text" name="Home" value="" />
</fieldset>
<fieldset>Mobile:
<input class="input" type="text" name="Mobile" value="" />
</fieldset>
<fieldset> Basic Salary:
<input class="input" type="number" name="BasicSalary" value="" />
</fieldset>
<fieldset> Allowance I:
<input class="input" type="number" name="Allowance1" value="" />
</fieldset>
<fieldset>Allowance II:
<input class="input" type="number" name="Allowance2" value="" />
</fieldset>
<fieldset>Total Day Rate:
<input class="input" type="number" name="DayRate" value="" />
</fieldset>
<fieldset>OT Rate:
<input class="input" type="number" name="OTrate" value="" />
</fieldset>
<fieldset>
<button name="submit" type="submit" id="submit">Insert</button>
<button onclick="goBack()" name="Back" type="back" id="details-back">Back</button>
</fieldset>
</form>
【问题讨论】:
-
嗨,我不明白你的问题,你现在在做什么?你想达到什么目标?
-
使用 Javascript/Jquery 从两个字段中获取值并将两个值的总和放入
Total Day Rate字段中。这很简单。试着弄脏你的手。 -
也添加您的 HTML 代码,您需要 javascript/jQuery 为您完成。
-
在基本工资和津贴 1 中输入值后,我想在总天数框中自动添加这两者。
-
get the addition of Basic Salary and Allowance I and insert it in Total Day Rate.... 像这样:` $result = $BasicSalary + $Allowance1;`$query = mysql_query("insert into attendance (DayRate) values ('$result')"); if($query!=false){ echo something about the success }else{ mysql errno etc... }老实说,您可以不在不刷新的情况下处理 php页面,因此您可能正在寻找一个 angular/JS/JQuery 方法来将值推送到您的数组中,然后再使用 post 方法提交它。