Jump to content

[SOLVED] INSERT checkbox values, one record per each...


elpaisa

Recommended Posts

Hi all!

 

Here is my problem.

 

I have a table called meds, and i want to insert records from different checkboxes with the same name but different values this is the structure of table

 

id      pharid      imageid

 

 

Now, the checkbox is the next

 

<input type="checkbox" name="imageid[]" value="'.$images['imageid'].'" > <b>'.$images['title'].'</b>

 

 

Well there are various checkboxes in the form dinamically generated from a query to another table, and i need to insert one record with imageid values into the field imageid of the table per each checkbox , and pharid that is from another var be inserted the same on each record.

 

 

Thnx all!

Help is much appreciated.

 

Link to comment
Share on other sites

sorry if i am not clear

 

what i really, really need is to insert each checkbox value into the table one record per each, the checkboxes are dinamically generated by a while loop and all has the same names but different values. so i don't know how to do this, becouse it has the same name it only inserts one record, all your need will be appreciated, if i don't explain very well is becouse i don't write english very well... so be patient, here is my code

 

Checkbox

<input type="checkbox" name="imageid[]" value="'.$images['imageid'].'" > <b>'.$images['title'].'</b>

 

  $imageid       = $_POST['imageid'][];
  $pharid        = $_POST['pharid'];
  
    if($imageid)
   { 
     foreach($_POST['imageid'] as $i) 
    { 

    $DB->query("INSERT INTO meds (medid, pharid, imageid)
                           VALUES('NULL', '$pharid', '$imageid[$i]')"); 
    } 
   } 

Link to comment
Share on other sites

  // Check if button name "Submit" is active, do this 
   if(count($_POST['imageid']<=0)
   { 
     foreach($_POST['imageid'] as $key => $value) { 
      $DB->query("INSERT INTO meds (medid, pharid, imageid) VALUES('NULL', '$pharid', '$value')"); 
    } 
   } 

 

that should work but the problem there is that $pharid' is always the same is that what you mean?

 

and note.. I'm also bad in english see it from my avatar

Link to comment
Share on other sites

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.