Click here to Skip to main content
15,888,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

This my code
PHP
<?php
//session_start();
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'];

///leave calculation
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.
PHP
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
Posted
Updated 20-Sep-12 4:52am
v2

You can't display Javascript alerts and do a header-based redirect at the same time.

Either display a full HTML page with the alerts on it, or use a header redirect to another page, passing in a value in the query string that causes alerts to be displayed.

You can use Javascript-based redirects on a page after the alert(s), but the whole idea of displaying Javascript alerts between pages is a bit messy.
 
Share this answer
 
At first I can see you are not specifying the javascript language anywere...

You should change the <script> to "<script language="javascript">

Then, I've not tried it, and I would tend to believe that this should solve the issue, but just in case:

SAMPLE like yours:
http://forums.devshed.com/javascript-development-115/calling-javascript-function-from-php-4718.html[^]

DIVIDE PROPOSAL in case your solution is not operative:
http://www.koderguru.com/tutorials/phptutorials/php_alertbox.php[^]
http://stackoverflow.com/questions/4246318/can-i-add-a-javascript-alert-inside-a-php-function-if-yes-how[^]
http://www.codingforums.com/showthread.php?t=193564[^]

Hope this helps. :thumbsup:
 
Share this answer
 
v2
Its because,it redirect the page and went to next page where java script alert code is not available.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900