prosesnya hampir sama dengan menampilkan data.
<?php
$conn = mysql_connect("localhost","root","blah");
mysql_select_db("test",$conn);
if($_POST){
$sql = "update album set judul='{$_POST['judul']}',artis='{$_POST['artis']}' where id='{$_POST['id']}'";
mysql_query($sql) or die('Gagal menyimpan album');
foreach($_POST['judul_lagu'] as $idTrack => $judul){
$sql = "update lagu set no_track='{$_POST['no_track'][$idTrack]}',judul='{$judul}',durasi='{$_POST['durasi'][$idTrack]}' where id='$idTrack'";
mysql_query($sql) or die('Gagal menyimpan lagu');
}
}
$edit_id = $_GET['id'];
$sql = "select * from album where id='$edit_id'";
$result = mysql_query($sql);
?>
<form method="post" action="">
<table cellpadding="5" cellspacing="0" border="1">
<tr>
<th>Judul</th>
<th>Artis</th>
</tr>
$album = mysql_fetch_array($result);
<tr>
<td><input type="text" name="judul" value="<?php echo $album['judul'];?>"/></td>
<td>
<input type="text" name="artis" value="<?php echo $album['artis'];?>"/>
<input type="hidden" name="id" value="<?php echo $album['id'];?>"/>
</td>
</tr>
<tr>
<td colspan="2">
<strong>Lagu: </strong>
<table cellspacing="0" cellpadding="3">
<tr>
<td style="border-bottom:1px solid #000;">No Track</td>
<td style="border-bottom:1px solid #000">Judul</td>
<td style="border-bottom:1px solid #000">Durasi</td>
</tr>
<?php
$rowset = mysql_query("select * from lagu where id_album='".$album['id']."'");
while($lagu = mysql_fetch_array($rowset)){
?>
<tr>
<td style="border-bottom:1px solid #000; border-right:1px solid #000">
<input type="text" name="no_track[<?php echo $lagu['id']?>]" value="<?php echo $lagu['no_track'];?>"/></td>
<td style="border-bottom:1px solid #000; border-right:1px solid #000">
<input type="text" name="judul_lagu[<?php echo $lagu['id']?>]" value="<?php echo $lagu['judul'];?>"/></td>
<td style="border-bottom:1px solid #000">
<input type="text" name="durasi[<?php echo $lagu['id']?>]" value="<?php echo $lagu['durasi'];?>"/></td>
</tr>
<?php }?>
</table>
</td>
</tr>
</table>
<input type="submit" value="update"/>
</form>