<?php 
	$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');
	
	mysql_selectDB("wauhaha_karaoke",$login);
	
	
	$c = $_POST['c'];
	$d = $_POST['d'];
	$t = $_POST['t'];
	

echo "<form method=post action=buyaction1.php>	
	<table align=center style='font-family:verdana;font-size:16pt'>
	<tr>	
		<td>Date :</td>
		<td>$d <input type=hidden name=d value=".$d."></td>
	</tr>
		<tr>	
		<td>Time :</td>
		<td>$t <input type=hidden name=t value=".$t.">
		<input type=hidden name=c value='$c'></td>
	</tr></table>
	<hr width=40%>
<table align=center style='font-family:verdana;font-size:16pt'>
<tr>
<td width=200 align=center>Product</td>
<td width=200 align=center>Quantity</td>
<td width=200 align=center>Price (RM)</td>
<td width=200 align=center>Total Price (RM)</td>

</tr>";
	
	for ($a=1; $a <$c; $a++)
{
$q=$_POST['q'.$a];
$p=$_POST['p'.$a];

$result = mysql_query("select * From kstock Where ProName = '$p' ");
$row=mysql_fetch_array($result);
$aaa = $row['RQuan'];
$aa1 = $aaa - $q;
if($aa1 <0){
echo "<script language=javascript>alert('Insufficient Stock!!');window.location='http://www.wauhaha.com/karaoke/sellfood.php'</script>";

}
	$pr = $row['sprice'];
	$tp = $q * $pr;
echo "<tr>
			<td align=center>$p <input type=hidden name=p$a value=$p></td>
			<td align=center>$q <input type=hidden name=q$a value=$q></td>
			<td align=center> $pr<input type=hidden name=pr$a value=$pr></td>
			<td align=center> $tp <input type=hidden name=tp$a value=$tp></td>
</tr>";

}
echo "<tr><td colspan=4 align=center><input type=submit value=Buy style='width:100;height:50'></td></tr></table>";

echo "</form>
<center><button onclick='window.print()' style='width:100;height:50'>Print</button></center>";