Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6792253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:56:47+00:00 2026-05-26T17:56:47+00:00

I have a list of checkboxes that I want to insert into a database,

  • 0

I have a list of checkboxes that I want to insert into a database, which I have processed as an array:

<input name="my_array[]" value="<?php echo $data['ID'] ?>" type="checkbox">
<?php echo $data['name'] ?><?php echo "br/>";

I’m getting my list of checkboxes from my database, and the selected checkboxes are being posted like so:

   $strFoo=$_POST['my_array'];

    $strBar = "";


    foreach ($strFoo as $strFooName) {

    $strBar .= $strFooName . ", ";
    }
    $strBar = substr($strBar, 0, -2);

Echoing, I get my list of ID’s selected like so 1, 2, 3, 4

My below foreach is unfortunately only inserting the first ID of the array only..

foreach ($strFoo as $strFooName) {

        $strSql="INSERT INTO table (ID) 
                 VALUES ('$strBar')";
    }

How can I insert each ID into my table?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:56:48+00:00Added an answer on May 26, 2026 at 5:56 pm

    It’d have to be:

    INSERT INTO table (ID) VALUES (1), (2), (3), (4)
    

    so your processing step would need to be

    $values = array();
    foreach ($strFoo as $strFooName) {
         $values[] = '(' . intval($strFooName) . ')';
    }
    
    $strBar = implode(',', $values);
    

    Note the addition of intval – that ensures that only valid numbers get inserted into the SQL statement. Your version was vulnerable to SQL injection attacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have List of Checkboxes which i want to create using FOR LOOP .
I have a list of checkboxes and I would want to make sure that
I have a List with Checkboxes and i want to every item on the
I have a list a simple dialog box which contains a few checkboxes, I
I have a that has a list of checkboxes and user can click any
I have a list of items that the user can select. I want it
I have a list of checkboxes, looking like this: <table> <tr><td><input type=checkbox /> <label>Bla</label></td></tr>
I have list of checkboxes that has all checkbox pre-checked when page load. Firstly,
I have a listbox of checkboxes that I want to iterate through and check
I have a list of input elements and using one selector I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.