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 6055047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:13:14+00:00 2026-05-23T08:13:14+00:00

I have fieldset with multiple checkboxes for a MySQL insert from a form. <fieldset

  • 0

I have fieldset with multiple checkboxes for a MySQL insert from a form.

<fieldset id="my_checkboxes"> 

        <legend>My Checkboxes (Select at least 2)</legend> 

        <label for="checkbox1"> 
            <input type="checkbox" id="checkbox1" value="yes" name="the_checkbox" /> 
            CheckBox #1
        </label> 

        <label for="checkbox2"> 
            <input type="checkbox" id="checkbox2" value="yes" name="the_checkbox2" /> 
            CheckBox #2
        </label> 

    </fieldset> 

I need to be able to have each checkbox have a unique NAME attribute because each checkbox inserts data into it’s own column in the database. (Otherwise, i would just use the the_checkbox[] as the name for each).

My problem is I need to have the user select at least 2 checkboxes in order to submit the form. Since I have seperate names for each, I cannot use the following code anymore as it counts by name:

$checkboxcount = count($_POST['the_checkbox']);
if($checkboxcount < 1)
{
    $errors[] = $checkboxcount;
}

MY SQL statement looks like this:

$sql = "INSERT INTO $db_table(the_checkbox,the_checkbox2) values 
(
'".mysql_real_escape_string(stripslashes($_REQUEST['the_checkbox']))."',
'".mysql_real_escape_string(stripslashes($_REQUEST['the_checkbox2']))."'
)";

What would you suggest for me to either A. Count checkboxes even with seperate Names, or B. keep the same name but somehow insert data into MySQL as seperate column names?

  • 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-23T08:13:15+00:00Added an answer on May 23, 2026 at 8:13 am

    If you prefer to keep different names, then do something like this:

    $chkbox_count = 0;
    if (isset($_POST['the_checkbox']) && $_POST['the_checkbox'] == "yes") $chkbox_count++;
    if (isset($_POST['the_checkbox2']) && $_POST['the_checkbox'] == "yes") $chkbox_count++;
    // etc...
    

    I would usually prefer to use use the same name for a related group of checkboxes though, with different values, but the way you are handing them directly into a SQL string makes your method of different names a little easier to handle.

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

Sidebar

Related Questions

I have a simple form: <form id=radio_form> <fieldset> <label><input type=radio name=color value=1 />Red</label><br />
I have a simple form: <div class=class_a> <fieldset> <label><input type=radio id=radio10 name=color value=1 />Red</label><br
I have a small contact form: <form method=post action=contact.php name=contactform id=contactform> <fieldset> <legend>Please fill
I have following html. <fieldset id=fieldset-step_3> <input type=text value=2 id=rule_form-lead_time name=rule_form[lead_time]> <select class=w50 id=rule_form-operator
I have the following form: <fieldset id=upload-form> <ul> <li> <div class=radio-list clearfix> <ul> <li><label
I'm trying to form a query string from multiple checkboxes that will be used
I have this basic HTML structure: <fieldset> <input/> <label></label> <div class=toggle_box> <div class=switch></div> </div>
I have the following code: <fieldset> <legend> <strong>Personal Information</strong> </legend> <ul> <li> <label for=first_name>First
I have a form like this : <fieldset> <legend> اضافه کردن یک قالب </legend>
I have a form and within it is this: <fieldset class=billing-address> <legend>Billing Address</legend> <ol>

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.