<?php 
	$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');
	
	mysql_selectDB("wauhaha_karaoke",$login);
	
	
	$c = $_POST['c'];
	$d = $_POST['d'];
	$t = $_POST['t'];
	
	
	
	for ($a=1; $a <$c; $a++)
{
$q=$_POST['q'.$a];
$p=$_POST['p'.$a];
$pr = $_POST['pr'.$a];
$tp = $_POST['tp'.$a];
$result =mysql_query("select * from kstock where ProName='$p'");
$row=mysql_fetch_array($result);
$l = $row['RQuan'];
$le = $l - $q;

$query=mysql_query("INSERT INTO sstock(date,time,ProName,ProPrice,Quan,Total)VALUE('$d','$t','$p','$pr','$q','$tp')");
if($le >=0){

$query1=mysql_query("Update kstock set RQuan ='$le' where ProName='$p'");
}
}


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

