Hi friends,
This my code
<?php
include ("../inserthistroy.php");
if(!isset($_SESSION["user_name"]))
{
header("Location:http://localhost/Mysql/Intranetportal/");
}
include ("../dbconfig.php");
$myname=$_SESSION["user_name"];
$query="select * from emp_leave_status where user_id='$myname'";
$data=mysql_query($query,$con) or die("Error in Query: " . mysql_error());
$num=mysql_fetch_array($data);
$user_id=$num['user_id'];
$user_name=$num['user_name'];
$designation=$num['designation'];
$total_leave=$num['total_leave'];
$cl=$num['cl'];
$sl=$num['sl'];
$pl=$num['pl'];
$cl_taken=$num['cl_taken'];
$sl_taken=$num['sl_taken'];
$pl_taken=$num['pl_taken'];
$cl_balance=$num['cl_balance'];
$sl_balance=$num['sl_balance'];
$pl_balance=$num['pl_balance'];
if(isset($_POST["Submit"]))
{
$leavetype=$_POST["leavetype"];
$nol=$_POST["nol"];
$start_date=$_POST["start_date"];
$end_date=$_POST["end_date"];
$reason=$_POST["reason"];
$query1 = "insert into apply_leave
(user_id,user_name, designation,apply_date,no_of_leave,leave_start_date,leave_end_date,status1,apply_time,leave_type,reason)
values('$myname','$user_name','$designation','$date1','$nol','$start_date','$end_date','pending','$time','$leavetype','$reason')";
mysql_query($query1,$con) or die("Error in query:". mysql_error());
if(isset($_POST['leavetype']))
{
if ($leavetype == 'PL') {
$nol=$_POST["nol"];
if($pl_balance<$nol)
{
echo "<script> alert('Unsufficient PL leave,Remaining Leave will be add in CL');</script>";
$bal_leave= $nol - $pl_balance;
$query9 = "update emp_leave_status set pl_balance = pl_balance - $pl_balance , pl_taken = pl_taken + $pl_balance where user_id = '$myname'";
$query10 = "update emp_leave_status set cl_taken = cl_taken + $bal_leave where user_id = '$myname'";
}
else if ($pl_balance>=$nol)
{
$query9 = "update emp_leave_status set pl_balance = pl_balance - $nol , pl_taken = pl_taken + $nol where user_id = '$myname'";
}
}
else if ($leavetype == 'SL') {
$nol=$_POST["nol"];
if($sl_balance<$nol)
{
echo "<script> alert('Unsufficient SL leave ,Remaining Leave will be add in CL');</script>";
$bal_leave= $nol - $sl_balance;
$query9 = "update emp_leave_status set sl_balance = sl_balance - $sl_balance , sl_taken = sl_taken + $sl_balance where user_id = '$myname'";
$query10 = "update emp_leave_status set cl_taken = cl_taken + $bal_leave where user_id = '$myname'";
}
else if ($sl_balance>=$nol)
{
$query9 = "update emp_leave_status set sl_balance = sl_balance - $nol , sl_taken = sl_taken + $nol where user_id = '$myname'";
}
}
else if ($leavetype == 'CL') {
$nol=$_POST["nol"];
$query9 = "update emp_leave_status set cl_taken = cl_taken + $nol where user_id = '$myname'";
}
mysql_query($query9);
@mysql_query($query10);
}
$_SESSION['leavetype']=$_POST['leavetype'];
$_SESSION['nol']=$_POST["nol"];
$_SESSION['start_date']=$_POST["start_date"];
$_SESSION['end_date']=$_POST["end_date"];
$_SESSION['reason']=$_POST["reason"];
header("Location:http://localhost/Mysql/Intranetportal/website/apply_leave-thanks.php");
}
?>
These two alert box not working when condition true but it redirect to other page.
echo "<script> alert('Unsufficient PL leave,Remaining Leave will be add in CL');</script>";
echo "<script> alert('Unsufficient SL leave ,Remaining Leave will be add in CL');</script>";
what should i do?
Any suggestion.
thanks