Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript PHP
Hi friends,
 
This my code
<?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.
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 20-Sep-12 2:03am
Edited 20-Sep-12 5:52am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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. Thumbs Up | :thumbsup:
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Its because,it redirect the page and went to next page where java script alert code is not available.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 485
1 BillWoodruff 330
2 OriginalGriff 310
3 Shweta N Mishra 244
4 Mathew Soji 225
0 OriginalGriff 6,153
1 Sergey Alexandrovich Kryukov 5,638
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,710


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100