<?php

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

$time_offset ="240"; 
$time_a = ($time_offset * 120);
$time = date("d-m-y, g:i a");

if ($_POST[val1] == "") {
   	echo "<script>alert('Please fill in your form completely')</script>";
	echo "<script language='javascript'>window.location='adminaddcredit.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'];
 $Username = $row2["Username"];
 $Name = $row2["Name"];
}
 
$credit = $_POST["val1"];
$CreID = $_POST["CreID"];
$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','$credit','$time','$result')");
if($query){
if($query2){
	echo "<script language=javascript>alert('Update successful!!');window.location='http://www.wauhaha.com/karaoke/adminviewmem.php'</script>";
}
}
echo "<script language=javascript>alert('Update fail!!');window.location='http://www.wauhaha.com/karaoke/adminviewmem.php'</script>";
	
	?>