Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.