hi evryone...
i have two tables first one is takeleave and the second one is leave...and when any employee
take leave by filling the leave form then according to the no. of days leave taken the value should be deducted from
another table i.e leave table.
but m unable to understand how to do it.....plz hlp me out......
table structure of leave table-----------
CREATE TABLE leave (
ecode varchar(15) NOT NULL default '',
CL int(5) NOT NULL default '0',
ML int(5) NOT NULL default '0',
EL int(5) NOT NULL default '0',
clv_days int(5) NOT NULL default '0',
mlv_days int(5) NOT NULL default '0',
elv_days int(5) NOT NULL default '0'
) TYPE=MyISAM;
table structu of takeleave table------
CREATE TABLE takeleave (
ecode varchar(15) NOT NULL default '',
leavetype varchar(15) NOT NULL default '',
des varchar(20) NOT NULL default '',
lv_from date NOT NULL default '0000-00-00',
lv_to date NOT NULL default '0000-00-00',
lv_days int(5) NOT NULL default '0'
) TYPE=MyISAM;
<html>
<body bgcolor="E6E6FA">
<?
mysql_connect("localhost","root","root");
mysql_select_db("master");
$ecode=$_POST['ecode'];
$CL=$_POST['CL'];
$ML=$_POST['ML'];
$EL=$_POST['EL'];
$clv_days=$_POST['clv_days'];
$mlv_days=$_POST['mlv_days'];
$elv_days=$_POST['elv_days'];
$leav="select leavetype from leave";
if($leav=='CL')
{
mysql_query("UPDATE leave SET CL = CL -clv_days;");
}
$result=mysql_query("select ecode,CL,ML,EL from leave");
echo "<table border='3'><BR><BR><BR><BR>
<tr>
<th >Code</th>
<th>CL</th>
<th>ML</th>
<th>EL </th>
</tr>" ;
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ecode'] . "</td>";
echo "<td>" . $row['CL'] . "</td>";
echo "<td>" . $row['ML'] . "</td>";
echo "<td>" . $row['EL'] . "</td>";
echo "</tr>";
}
mysql_close();
?>
</body>
</html>
<HTML>
<HEAD>
<TITLE>New Document</TITLE>
</HEAD>
<BODY>
<?php
$ecode = $_POST["ecode"];
$leavetype= $_POST["leavetype"];
$des =$_POST["des"];
$lv_from=$_POST["lv_from"];
$lv_to=$_POST["lv_to"];
$lv_days=$_POST["lv_days"];
//$left=$_POST["asubdpt"];
mysql_connect("localhost","root","root");
mysql_select_db("master");
$query="INSERT INTO Takeleave VALUES ('$ecode','$leavetype','$des','$lv_from','$lv_to','$lv_days')";
if (mysql_query($query))
{
echo "record added!";
include("displayleaves.php");
}
else
{
echo "something went wrong";
}
mysql_close();
?>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>New Document</TITLE>
<script type="text/javascript">
function validate_form ( )
{
valid = true;
if ( document.myform.ecode.value == "" )
{
alert ( "Please fill in the 'Code' box." );
myform.ecode.focus();
valid = false;
return valid;
}
if ( document.myform.lt.value == "" )
{
alert ( "Please select the leave type" );
myform.lt.focus();
valid = false;
return valid;
}
if ( document.myform.des.value == "" )
{
alert ( "Please fill in the Description box." );
myform.des.focus();
valid = false;
return valid;
}
if ( document.myform.lv_from.value == "" )
{
alert ( "Please enter the starting dat of leave" );
myform.lv_from.focus();
valid = false;
return valid;
}
if ( document.myform.lv_to.value == "" )
{
alert ( "Please enter the ending date of leave" );
myform.lv_to.focus();
valid = false;
return valid;
}
</script>
</HEAD>
<BODY bgcolor="E6E6FA" onLoad="myform.ecode.focus()";>
<form action="emplvins.php" method="POST" name="myform" onsubmit="return validate_form();">
<h2> <p align="center"> Leave Form </p></h2>
<table align="center"> <tr> <th> Employee Code: </th>
<td> <input type="text" size="20" name="ecode" value=""></td> </tr>
<tr> <th> Leave Type: </th>
<td><select size="1" name="leavetype">
<option>---Select---</option>
<option>Casual Leave</option>
<option>Earned Leave</option>
<option>Medical Leave</option>
</select> </td></tr>
<tr><th> Description:</th>
<td><textarea name="des" size="20" value=""></textarea>
<tr> <th> Leave From: </th>
<td> <input type="text" size="20" name="lv_from" value=""> yyyy-mm-dd</td> </tr>
<tr> <th> Leave To: </th>
<td> <input type="text" size="20" name="lv_to" value=""> yyyy-mm-dd</td> </tr>
<tr> <th> Leave Days: </th>
<td> <input type="text" size="20" name="lv_days" value=""></td> </tr>
<td> <td> <input type="submit" value="Submit"> </td>
</table>
</form>
</BODY>
</HTML>