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

	FOREACH($_POST['name'] as $i=>$value)
	{

		$query2 = "UPDATE `Bmember` SET `name` = '$name[$i]' WHERE `bName` = '$bName' AND `seq` = '$i'"; 
		mysql_query($query2,$connect);
		
		$query5 = "SELECT * FROM `Bmember` WHERE bName` = '$bName' AND `seq` = '$i'";
		$result = mysql_query($query5,$connect);
		if(empty($result))
		{
			$query7 = "INSERT INTO `Bmember` VALUE ('$bName','$i','$name[$i]','$talent[$i]')";
			mysql_query($query7,$connect);
		}
	}
	
	FOREACH($_POST['talent'] as $i=>$value)
	{
		$query6 = "SELECT * FROM `Bmember` WHERE bName` = '$bName' AND `seq` = '$i'";
		$result = mysql_query($query6,$connect);
		if(!($result))
		{
			$query2 = "UPDATE `Bmember` SET `talent` = '$talent[$i]' WHERE `bName` = '$bName' AND `seq` = '$i'"; 
			mysql_query($query2,$connect);
		}
	}
	
	$query4 = "INSERT INTO `AddModify1` VALUES ('$mId','$bName','$seq',NOW())"; 
	mysql_query($query4,$connect);
	
	echo "<Script language='javascript'>";
	echo "alert('資料修改成功！');";
	echo "location.href='b_show.php?bName=".$bName."';";
	echo "</script>";
?>

