<?php

	$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');
	
	mysql_selectDB("wauhaha_karaoke",$login);
	$CreID = $_POST['CreID'];

$time=date("Y-m-d");
	$MemID=$_GET['MemID'];
$result4 = mysql_query("SELECT * FROM regmember Where MemID='$MemID' ");
if($row4 = mysql_fetch_array($result4)){
$Name=$row4["Name"];
$Credit = $row4["Credit"];
$Username= $row4['Username'];
}
$c = $_POST['val1'];
if ($_POST[val1] == "") {
   	echo "<script>alert('Please fill in your form completely')</script>";
	echo "<script language='javascript'>window.location='staffaddcredit.php?MemID=$MemID'</script>";die;
}

$result2 =mysql_query("SELECT * FROM regmember WHERE MemID='$MemID'");
if($row2 = mysql_fetch_array($result2)){
  
  
  $result = $_POST[val1] + $row2['Credit'];
  
}
 


$query =mysql_query("UPDATE regmember SET Credit = '$result' WHERE MemID='$MemID'	");
$query2 =mysql_query("Insert INTO credittran(CreID,MemID,Username,Name,AddCredit,AddCreditD,BalCredit)VALUE('$CreID','$MemID','$Username','$Name','$c','$time','$result')");
if($query){
	echo "<script language=javascript>alert('Update successful!!');window.location='http://www.wauhaha.com/karaoke/staffviewmem.php'</script>";
}
echo "<script language=javascript>alert('Update fail!!');window.location='http://www.wauhaha.com/karaoke/staffviewmem.php'</script>";
	
	?>