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

  • Home
  • SEARCH
  • 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 8132135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:16:22+00:00 2026-06-06T09:16:22+00:00

Hi i am generating checkbox list by using a for each loop, I want

  • 0

Hi i am generating checkbox list by using a for each loop, I want to pass the value of checked checkbox into database.

foreach($this->lis as $lst)
 {?>
  <tr>
    <td>
     <input type="checkbox" name="list" value="1" />
         <label for="list_32"><?php echo $list->nList ?></label>
    </td>
  </tr>
 <?php } ?>

when i checked the checkbox i want to pass the label name into the database can someone help.

  • 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-06-06T09:16:25+00:00Added an answer on June 6, 2026 at 9:16 am

    Ok, you’ve got a few problems there..

    Firstly, please avoid opening php tags and closing them constantly. Just echo back the HTML. Going in and out of php so often will cause performance issues.

    So, first off, you need to set up a form on here, your form needs to point to a second page (or self-process using an isset function, but let’s go with the former solution for clarity). The second page is what’s going to dump things into the DB for you based on what the user ticked.

    So, here’s the HTML for your form;

    <form action="database.php" method="POST">
        <div>
            <label for="checkbox1">This is the first option:</label>
            <input type="checkbox" id="checkbox1" name="checkbox1" />
        </div>
        <div>
            <label for="checkbox2">This is the second option:</label>
            <input type="checkbox" id="checkbox2" name="checkbox2" />
        </div>
        <div>
            <input type="submit" />
        </div>
    </form>
    

    Again, I’d recommend echo’ing this back in your foreach loop – a short function could accomplish this for you.

    So, once someone hits the “Submit” button, they’ll be taken to your second page (database.php as we’ve called it), and their options will be stored in the POST array. For good practice, always use POST rather than GET when dealing with DB entries.

    So on this page, we’d check what checkboxes were selected, and then update the db as required;

    if (isset($_POST['checkbox1']))
    {
        // user ticked checkbox1
        $sql = "UPDATE table
                SET 'checkbox1' = 1
                WHERE 'user' = 'username';"
        mysqli_query($sql); 
    }
    

    Note that’s just a rough solution – you haven’t told me exactly how you’re doing this, so I’m assuming your DB is tied to user’s votes etc. You can also update checkbox1 by incrementing the value.. etc etc.

    Hope this helps.

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

Sidebar

Related Questions

I am using <t:selectManyCheckbox> and <t:checkbox> for checkbox generating. <t:selectManyCheckbox id=selectone value=#{templatePrescriptionMaintenanceBackingBean.objectID} layout=spread styleClass=table
Short Generating table with barcodes of items. Each item has exact quantity in database
I'm generating an unknown amount of checkboxes in my form using mysql, this number
I want to validate Checkbox in javascript, checkboxes is generating dynamically by PHP and
I am generating the html using JSON file. Now I need to pass data
I am generating a checkbox using the corresponding method of CHtml , and I
Does someone have a complete list of model types that be specified when generating
I am having some trouble generating a web form using fields specified in an
To avoid reinventing the wheel, I am generating a form using CakePHP's form helper,
When generating IL using DynamicMethod it's possible to call methods and access fields that

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.