mercredi 11 mai 2016

Send values to db when multiple checkboxes are checked

I am loading some data from a db table to checkboxes. When a user checks boxes and submits, the values from these checkboxes need to be added to a different table. With the code I have now, I am able to send values of one checked box. What am I missing in sending the values of all the checked checkboxes?

<table>
    <?php       
    $q5=mysqli_query($link,"SELECT * FROM brands_offer WHERE Brand_Id='$bid' AND Published='1' ");
    while($row5 = mysqli_fetch_array($q5)){
        $catid= $row5['Catg_Id'];
        $subcatid= $row5['Subcatg_Id'];
        $pid= $row5['Product_Id'];      
    ?><tr><td>
    <form action="store-admin.php?search=<?php echo $stname;?>#stock" method="post">
    <input type="checkbox" name="checkbox" value="<?php echo "$bname,$catid,$subcatid,$pid";?>" >
    <?php
        echo $bname;
        echo " ->  ";
        echo $catid;
        echo ",  ";
        echo $subcatid;
        echo ",  ";
        echo $pid;
        echo "  ";
    }
    ?></td></tr>
    <input type="submit" value="Save Changes" name="add" >
    </form>
    </table>
    <?php
    if(isset($_POST['add']))
    {
    $chk = $_POST['checkbox'];

    $val = explode(",",$chk);
    $bn = $val[0];
    $cid= $val[1];
    $scid= $val[2];
    $prid= $val[3];

    echo "<script type='text/javascript'>alert('brand: ". $bn."')</script>";
    echo "<script type='text/javascript'>alert('cat: ". $cid."')</script>";
    echo "<script type='text/javascript'>alert('sub: ". $scid."')</script>";
    echo "<script type='text/javascript'>alert('pr: ". $prid."')</script>";

    }?>




Aucun commentaire:

Enregistrer un commentaire