dimanche 24 juillet 2016

How to Insert Primary key from checkbox

I want to input the data into the table id_ss ss_kat and enter ss_kat id_kat on the table, so the data will be displayed on the input kat ss_kat the checkbox menu, but I have tried repeatedly 2 can not, there are approximately erornya where?

enter image description here

I want to submit the checkbox in table kat and sample index from image here

enter image description here

<?php
    include "../../inc/conn.php";
?>

<div class="row">
<div class="col-md-6">
    <form action="proses.php" method="POST" enctype="multipart/form-data" style="margin-top:20px;">
            <input type="hidden" name="id_ss_kat" />
        <?php


                $ss = mysql_query("SELECT * from ss");
        ?>
                <select class="form-control" name="id_ss">
                <?php
                    while ($rows=mysql_fetch_array($ss)) 
                    { ?>
                        <option class="form-control" value="<?php echo $rows['id_ss'];?>" name="id_ss"><?php echo $rows['name'];?>
                        </option>

                    <?php
                        }
                ?>
                </select>
                <br>
        <?php
                $kat = mysql_query("SELECT * from kat WHERE kat_status='1'");
        ?>

                    <?php
                        while ($rows=mysql_fetch_array($kat)) 
                    { ?>

                            <input type="checkbox" name="id_kat[<?php echo $rows['id_kat'];?>]" value="<?php echo $rows['id_kat'];?>"><?php echo $rows['nama'];?>

                    <?php
                            }
                    ?>

                <br>
        <input class="btn btn-primary" type="submit" name="ssf" value="SAVE">
        <br>
    </form> 
    <br>

</div>
</div>

and here is proses.php

    <?php
                if (isset($_POST['ssf'])) {
                        $id_ss_kat                      = $_POST['id_ss_kat'];
                        $id_kat                         = $_POST['id_kat'];
                        $id_ss                          = $_POST['id_ss'];
                        
                        foreach($id_kat as $kat) {
                            $source.=$kat.", ";
                        }
                        $one=substr($source,0,-1);
                                                                        
                        $q              = "INSERT into ss_kat VALUES('$id_ss_kat','$one','$id_sekolah')";
                        $dq     = mysql_query($q);
                        
                        if ($dq) {
                                echo "berhasil";
                        }else{
                                mysql_error();
                        }

                }
        ?>
the index look like in the picture below:

enter image description here




Aucun commentaire:

Enregistrer un commentaire