freeloader
freeloader

Reputation: 346

how to insert multiple data to mysql using checkbox corresponding value?

i have been trying to insert multiple values to mysql using checkbox. my code goes like this.

    <form name='form' method='post'>
    <table>
    <?php
    $id=$_REQUEST['ID'];
    $sql=mysql_query("SELECT * FROM table WHERE id='".$id."'");
    while($row=mysql_fetch_array($sql)){
    ?>
    <tr>
    <td><input type="checkbox" name="select[]" value="<?php echo "$id"; ?>"/></td>
    <td><?php echo $row['shapes']; ?></td>
    <td><?php echo $row['area']; ?></td>
    <td><?php echo $row['characteristic']; ?></td>
    </tr>
    </form>
    <?php
    }//end whil loop
    ?>
    <tr>
    <td><input type="submit" name="submit" value="submit" class="del"/>      
    </td>
    </tr>
    </table>

    <?php
    if(isset($_POST['submit'])){
    $select[] = $_POST['select'];
    $select=$_POST['select'];

    for($i=0;$i<sizeof($select);$i++){
       $query=mysql_query("INSERT INTO table2(id, shapes, area, characteristic)
       VALUES('".$select[$i]."', '".$row['shapes']."', 
            '".$row['area']."', '".$row['characteristic']."')");
    }//end for loop
   }
   ?>

i was able to correctly insert the checkbox value to table2 but the problem is, those values that go to shapes, area, characteristic fields are not the corresponding values. The values that are being inserted are the values of the last data from table. please help. only the checkbox value are being inserted correctly.

Upvotes: 0

Views: 4670

Answers (1)

freeloader
freeloader

Reputation: 346

Oh, I get it. I have to add a hidden button for the other fields. Thanks.

Upvotes: 0

Related Questions