Hi to All, I am performing calculation which i echo it in the input form to insert it to DB table The calculation works fine when i submit the form but the it does not correct calculation to the DB. it seems that the isert to database is done before the calculation and I can't figure a way around it. Because i'm submitting to the same page, the calculation populate in the input form correctly but it insert Zero to the database table instead of correct calculation populated in the input field to DB table You could see from the line 114 to 116 that, i'm performing some calculations and echo it at line 128 and line 128 in the input form value field. Please any help on how to do this...All the function in the code is in another file and it works fine...so the only program is that the calculated value is not inserted as expected Here is the code
<?php
include 'core/initForMainLogPage.php';
if(isset($_GET['empId']) && !empty($_GET['empId'])){
//delete employee here
$empId=$_GET['empId'];
grabEmpId($empId);
}
?>
<?php
if(logged_in()){
$data=user_dataManager('username');
$usernameData=$data['username'];
}else{
header('Location: index.php');
}
?>
<?php include 'includes/adminHeadAll.php';?>
<header>
<?php include 'includes/managerMenu.php';?>
</header>
<div class="container">
<br/>
<h3>Pay Employee</h3>
<?php
$error=array();
$errorAll='';
$leave="";
if(isset($_POST['empId']) && isset($_POST['name']) && isset($_POST['date']) && isset($_POST['basicSalary'])
&& isset($_POST['leave']) && isset($_POST['salaryPerDay']) && isset($_POST['leaveDeduct'])
&& isset($_POST['netSalary'])){
$empId=htmlentities(mysql_real_escape_string($_POST['empId']));
$name=htmlentities(mysql_real_escape_string($_POST['name']));
$date=htmlentities(mysql_real_escape_string($_POST['date']));
$basicSalary=htmlentities(mysql_real_escape_string($_POST['basicSalary']));
$leave=htmlentities(mysql_real_escape_string($_POST['leave']));
$salaryPerDay=htmlentities(mysql_real_escape_string($_POST['salaryPerDay']));
$leaveDeduct=htmlentities(mysql_real_escape_string($_POST['leaveDeduct']));
$netSalary=htmlentities(mysql_real_escape_string($_POST['netSalary']));
//checking for the validity of data entered
if(empty($leave) || empty($date)){
$error[]='Pleave leave or date field is empty.';
}else{
if(preg_match('/[0-9]/',$leave)==false){
$error[]='Leave should only contain numbers';
}
if(empId($empId)===false){
$error[]="This employee is not recoganize by the system and can not be paid,he may need to register first.";
}
}
if(!empty($error)){
$errorAll= '<div class="error"><ul><li>'.implode('</li><li>',$error).'</li></ul></div>';
}else{
//this funciton insert into database
payrollData($name,$empId,$date,$basicSalary,$leave,$salaryPerDay,$leaveDeduct,$netSalary);
echo '<p class="pa">Payment made successfully. <a href="employees-salary-report.php">See Payment Records</a></p>';
}
}//end isset
?>
<div class="tableWrap">
<form action="" method="post" >
<div class="styletable"><table cellpadding="" cellspacing="" border="0">
<?php
$query=mysql_query("SELECT
empId,name,level,company.compId,company.levelOne,company.levelTwo,
company.levelThree,company.levelFour,company.levelFive
FROM employee JOIN company ON company.compId=1 WHERE empId='$empId' LIMIT 1");
while($row=mysql_fetch_array($query)){
$empId=$row['empId'];
$name=$row['name'];
$levelEmp=$row['level'];
$levelOne=$row['levelOne'];
$levelTwo=$row['levelTwo'];
$levelThree=$row['levelThree'];
$levelFour=$row['levelFour'];
$levelFive=$row['levelFive'];
if($levelEmp==1){
$levelPay=$levelOne;
}elseif($levelEmp==2){
$levelPay=$levelTwo;
}elseif($levelEmp==3){
$levelPay=$levelThree;
}elseif($levelEmp==4){
$levelPay=$levelFour;
}elseif($levelEmp==5){
$levelPay=$levelFive;
}
//making calculations here
$basicSalary=$levelPay * 30;
$leaveDeduct=$leave * $levelPay;
$netSalary=$basicSalary - $leaveDeduct;
}
?>
<tr><td>Employee ID: </td><td><input type="text" name="empId" readonly="readonly" value="<?php if(isset($empId)){echo $empId;}?>"></td></tr>
<tr><td>Employee: </td><td><input type="text" name="name" readonly="readonly" value="<?php if(isset($name)){ echo $name;}?>"></td></tr>
<tr><td>Date: </td><td><input type="text" id="Date" class="picker" name="date"></td></tr>
<tr><td> Basic Salary: </td><td><input type="text" name="basicSalary" readonly="readonly" value="<?php echo $basicSalary;?>"></td></tr>
<tr><td> No. Of Absent: </td><td><input type="text" name="leave" class="input" value=""></td></tr>
<tr><td> Salary Per Day:</td><td><input type="text" name="salaryPerDay" readonly="readonly" value="<?php echo $levelPay;?>"></td></tr>
<tr><td> Deduction For Absentee:</td><td><input type="text" name="leaveDeduct" readonly="readonly" value="<?php echo $leaveDeduct;?>"></td></tr>
<tr><td> Net Salary:</td><td><input type="text" name="netSalary" readonly="readonly" value="<?php echo $netSalary;?>"></td></tr>
<tr><td> </td><td><input type="submit" value="Submit Pay" class="submit" name="pay"></td></tr>
</table></div>
</form>
<?php
?>
</div>
<br />
<?php echo $errorAll; ?>
<p>Manage the monthly salary details of your employee along with the allowances, deductions, etc. by just entering their leave</p>
</div>
<?php include 'includes/footerAll.php';?>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/ui.js"></script>
</body>
</html>