<?php 

$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');
	
mysql_selectDB("wauhaha_karaoke",$login);
$id=$_GET['id'];
$name = $_POST['name'];
$y = $_POST['y'];
$l = $_POST['l'];

$rr = mysql_query("select id from leave2 where id='$name'");

if(mysql_num_rows($rr) == 1){
			echo "<script language='javascript'>alert('The ID already insert.')</script>";
			echo "<script language='javascript'>window.location='inlev.php?id=$id'</script>";die;
}

if($l==""){
			echo "<script language='javascript'>alert('Please Insert Completely.')</script>";
			echo "<script language='javascript'>window.location='inlev.php?id=$id'</script>";

}else{

$query =mysql_query("INSERT INTO leave2(id,l,year)Values('$id','$l','$y')");

if($query){
			echo "<script language='javascript'>alert('Insert Success.')</script>";
			echo "<script language='javascript'>window.location='lset.php?id=$id'</script>";

}else{
			echo "<script language='javascript'>alert('Insert Fail.')</script>";
			echo "<script language='javascript'>window.location='lset.php?id=$id'</script>";
}
}
?>