<?php

	$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');

	mysql_selectDB("wauhaha_karaoke",$login);
	$ProID=$_GET['ProID'];
	$Quan =$_POST['quan'];
	$Use =$_POST['use'];
	$Remain = $Quan - $Use;
	
	
	if($Use==""){
				echo "<script>alert('Please fill in your form completely')</script>";
				echo "<script language='javascript'>window.location='editstockuse.php?ProID=$ProID'</script>";
	
	}else{
	if(!is_numeric($Use)){
				echo "<script>alert('Please Use Numeric')</script>";
				echo "<script language='javascript'>window.location='editstockuse.php?ProID=$ProID'</script>";
	
	
	
	
	
	}else{
	if($Remain <= 0){
				echo "<script>alert('Insufficient Stock')</script>";
				echo "<script language='javascript'>window.location='editstockuse.php?ProID=$ProID'</script>";
	
	
	
	}else{
	
	$query=mysql_query("UPDATE stockuse SET ProUsed='$Use', ProRemain='$Remain' where ProID='$ProID'");
	$query2=mysql_query("UPDATE stock SET ProRQuan='$Remain' where ProID='$ProID'");

	if($query){
	echo "<script language=javascript>alert('Update successful!!');window.location='http://www.wauhaha.com/karaoke/stock.php'</script>";
}else 
echo "<script language=javascript>alert('Update fail!!');window.location='http://www.wauhaha.com/karaoke/stock.php'</script>";
	
	
	
	
	}
	}
	}
	
	?>