vendredi 3 février 2017

edit checkbox and insert to database mysql php

I would like change checkbox my source code: 1 query displays checkboxes checked, which are in database 2 query displays checkboxes which not checked, because arent't in database 3 query insert to database which are checked, but send only checkboxes, which were checked before

$zap1="SELECT * FROM  oferta left join oferta_gastro on oferta_gastro.id_oferty=oferta.id_oferty  where id_gastronomi=".$_GET['edit_id'];
    $result_set1 = mysqli_query($connect, $zap1);
    $i=0;
    while($row=mysqli_fetch_array($result_set1))
    {
    echo '<td><input type="checkbox" name="'.($row['id_oferty']).'" checked/> '.($row['nazwa_oferty']).'</td>';
    $i++;
    if($i%3==0)
    {
    echo '</tr><tr>';
    }
    }

    echo '</tr><tr>';
    $zap2="SELECT * FROM kategorie_ofert,gastronomia, oferta left join oferta_gastro on oferta_gastro.id_oferty=oferta.id_oferty where  kategorie_ofert.id_kat_oferty=oferta.id_kat_oferty and kategorie_ofert.id_kat_oferty=1 and oferta_gastro.id_oferty is NULL and gastronomia.id_gastronomi=".$_GET['edit_id'];
    $result_set2 = mysqli_query($connect, $zap2);
    $i=0;
    while($row=mysqli_fetch_array($result_set2))
    {
    echo '<td><input type="checkbox" name="'.($row['id_oferty']).'" /> '.($row['nazwa_oferty']).'</td>';
    $i++;
    if($i%3==0)
    {
    echo '</tr><tr>';
    }
    }


   $get_tasks = "SELECT * FROM oferta where id_kat_oferty=1";
$result_set2 = mysqli_query($connect,$get_tasks);

while($row2=mysqli_fetch_array($result_set2))
    {
    if (isset($_POST[$row2['id_oferty']]))
    {
    $dopisz_rekord= "INSERT INTO oferta_gastro (id_oferty,id_gastronomi) VALUES ('".($row2['id_oferty'])."','$id_gastronomi'); ";
    $result=mysqli_query($connect, $dopisz_rekord);  
    echo $dopisz_rekord;  
        }
    }

Aucun commentaire:

Enregistrer un commentaire