Updating data in two tables. one that contains multiple data in one column

I am trying to update my data inside two tables at once (maklumatakaun, detailakaun) in detail. There is a column "KodLokasi" "KodJenisAkaun" and "NoTelefon", which can have more than one data entry under one identifier. That's what i got so far

extract ($_POST);

if ($_POST) {

    $NoAkaun            = isset($_POST['NoAkaun'])          ? $_POST['NoAkaun'] : '';
    $KodBahagian        = isset($_POST['KodBahagian'])      ? $_POST['KodBahagian'] : '';
    $Tarif              = isset($_POST['Tarif'])            ? $_POST['Tarif'] : '';
    $KodDaerah          = isset($_POST['KodDaerah'])        ? $_POST['KodDaerah'] : '';
    $KodKategori        = isset($_POST['KodKategori'])      ? $_POST['KodKategori'] : '';
    $NoTelefon          = isset($_POST['NoTelefon'])        ? $_POST['NoTelefon'] : '';
    $KodLokasi          = isset($_POST['KodLokasi'])        ? $_POST['KodLokasi'] : '';
    $KodJenisAkaun      = isset($_POST['KodJenisAkaun'])    ? $_POST['KodJenisAkaun'] : '';
    $akaun_id           = isset($_POST['akaun_id'])         ? $_POST['akaun_id'] : '';






    $sql = mysql_query("UPDATE maklumatakaun
                        SET NoAkaun = '$NoAkaun' , 
                        KodBahagian = '$KodBahagian' , 
                        KodDaerah = '$KodDaerah' , 
                        KodKategori = '$KodKategori' , 
                        Tarif = '$Tarif' , 
                        WHERE id = '$id'");
    $akaun_id = mysql_insert_id();
    foreach ($NoTelefon AS $i => $telefon){
    $sql= mysql_query ("UPDATE detailakaun
                        SET KodJenisAkaun = '$KodJenisAkaun[$i]' ,  
                        KodLokasi = '$KodLokasi[$i]' , 
                        NoTelefon = '$telefon'
                        ");

This code will update all columns within two tables, but it can be said that one account was registered with 3 'KodLokasi', 'KodJenisAkaun' and 'NoTelefon', and then when it is updated with only one of 3 columns, it will repeat 3. How can I update this correctly?

+4
source share
1
foreach ($NoTelefon AS $i => $telefon){
$sql= mysql_query ("UPDATE detailakaun
                    SET KodJenisAkaun = '$KodJenisAkaun[$i]' ,  
                    KodLokasi = '$KodLokasi[$i]' , 
                    NoTelefon = '$telefon'
                    ");

$NoTelefon 3 foreach 3

1

$sql= mysql_query ("UPDATE detailakaun
                    SET KodJenisAkaun = '$KodJenisAkaun[1]' ,  
                    KodLokasi = '$KodLokasi[1]' , 
                    NoTelefon = '$NoTelefon[1]'
                    ");

, ,

0

All Articles