Jump to content

Multiple Insert or Update


dhimok

Recommended Posts

Hi every one.

 

I have this form and i want to do a multiple insert using checkboxes. The values are fetched from a tbl1 and will be inserted into another table tbl2.

I want to get only those fields where checkbox next to it is selected

 


<form>
<?php
$sql = mysql_query("Select id, field FROM tbl1");

while(list($id,$field) = mysql_fetch_array($sql)) {

echo '
<p>
    <input type="checkbox" name="selected_flds[]" value="'.$id.'" />
    <input type="text" name="field[]" value="'.$field.'" />
</p>
  ';
} // end while
?>
</form>

 

thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/54753-multiple-insert-or-update/
Share on other sites

As you can see from the above code I am looping thru records and the form will look like this:

 


<form>

<p>
    <input type="checkbox" name="selected_flds[]" value="1" />
    <input type="text" name="field[]" value="field1" />
</p>
<p>
    <input type="checkbox" name="selected_flds[]" value="2" />
    <input type="text" name="field[]" value="field2" />
</p>

<p>
    <input type="checkbox" name="selected_flds[]" value="3" />
    <input type="text" name="field[]" value="field3" />
</p>

.... etc.

</form>

 

I would do something like this:

 


<?php
foreach ($_POST['selected_flds'] as $key => $value) {

// update where id=$value
}

?>

 

But this updates all records. I want only with checkboxes checked. So here I am stuck

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.