<?
	$mId = $_POST['mId'];
	$bName = $_POST['bName'];
	$aName = $_POST['aName'];
	
	require_once('link.php');
	mysql_select_db($database,$connect);
	
	if( ($_FILES['aPhoto']['error'][0] == UPLOAD_ERR_OK )) //如果有上傳,即處理這張照片
	{ 
		$userfile_1 = $_FILES['aPhoto']['tmp_name'][0]; //上傳圖檔(暫存位置)
        $upfile_1 = "./pic/album_pic/".$_FILES['aPhoto']['name'][0]; //檔案上傳後的位置+檔案名稱
          
        if( (move_uploaded_file($_FILES['aPhoto']['tmp_name'][0], $upfile_1)))
        {	
        	echo "UPLOAD DONE  " . $_FILES['aPhoto']['name'][0] ;
        }else{
			echo "UPLOAD FAIL 101 " ;
		}
	}else{
		echo "UPLOAD FAIL 102 " ;
	}
	$upfile_2 = "/pic/album_pic/".$_FILES['aPhoto']['name'][0];
	
	if(	$upfile_2 == '/pic/album_pic/')
	{
		$content = addslashes(nl2br($content));
		$query1 = "UPDATE `Album` SET `aDate` = '$aDate',`company` = '$company' WHERE `bName` = '$bName' AND `aName` = '$aName'";
		mysql_query($query1,$connect);
	}
	else
	{
		$content = addslashes(nl2br($content));
		$query1 = "UPDATE `Album` SET `aDate` = '$aDate',`company` = '$company',`aPhoto` = '$upfile_2' WHERE `bName` = '$bName' AND `aName` = '$aName'";
		mysql_query($query1,$connect);
	}
	
	FOREACH($_POST['song'] as $i=>$value)
	{

		$query2 = "UPDATE `Song` SET `song` = '$song[$i]' WHERE `bName` = '$bName' AND `aName` = '$aName' AND `seq` = '$i'"; 
		mysql_query($query2,$connect);
		
		$query5 = "SELECT * FROM `Sog` WHERE WHERE `bName` = '$bName' AND `aName` = '$aName' AND `seq` = '$i'";
		$result = mysql_query($query5,$connect);
		if(empty($result))
		{
			$query7 = "INSERT INTO `Song` VALUE ('$bName','$aName','$i','$song[$i]')";
			mysql_query($query7,$connect);
		}
	}
	
	$query4 = "INSERT INTO `AddModify2` VALUES ('$mId','$bName','$aName','$seq',NOW())"; 
	mysql_query($query4,$connect);
	
	echo "<Script language='javascript'>";
	echo "alert('資料修改成功！');";
	echo "location.href='a_show.php?bName=".$bName."&aName=".$aName."';";
	echo "</script>";
?>