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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:55:08+00:00 2026-06-11T16:55:08+00:00

I have 4 checkboxes and suppose I check only two of them i.e user1

  • 0

I have 4 checkboxes and suppose I check only two of them i.e user1 and user3

<input type="checkbox" name="usersp[]" value="1" checked="checked" />User1 <br>
<input type="checkbox" name="usersp[]" value="2"/>User2 <br>
<input type="checkbox" name="usersp[]" value="3" checked="checked" />User3 <br>
<input type="checkbox" name="usersp[]" value="4"/>User4 <br>

and I have two fields (“User_id”,”Selected”) in my database, below is my insert code

foreach($_POST['usersp'] as $user_id) {
  $sql = "INSERT INTO sel_users(`User_id`,`Selected`) VALUES('$user_id','')";
  $result = mysql_query($sql);
}

My question is how would I insert checked user as value of 1 and other as value of 0 in “Selected” field?

  • 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-11T16:55:09+00:00Added an answer on June 11, 2026 at 4:55 pm

    You can’t know the (unselected checkboxes) unless you are already know them

    Here the only way that can make your dream real

    //YOUR USERS IDS
    $userIDS=array('1','2','3','4');
    //CHECKED USERS ARRAY
    $checkedUsers=array('1','3');
    
    if(!isset($_POST['usersp'])){
    foreach($userIDS as $userID){
        //IF IT IN CHECK ARRAY, CHECK IT!
        $checked=(in_array($userID,$checkedUsers))?' checked="checked"':'';
        echo '<input type="checkbox" name="usersp[]" value="'.$userID.'"'.$checked.' />';
    }
    }
    
    else{
        foreach($userIDS as $userID){
            //USER SELECTED OR NOT?
            $selected=(in_array($userID,$_POST['usersp']))?'1':'0';
            $sql = "INSERT INTO sel_users(`User_id`,`Selected`) VALUES('$user_id','$selected')";
            $result = mysql_query($sql);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following HTML: <form id=myform> <input type='checkbox' name='foo[]'/> Check 1<br/> <input
For example, i have checkboxes: <input type='checkbox' name='fruit' value='apple'> Apple <input type='checkbox' name='fruit' value='orange'>
I have the following checkbox created by a loop: <input type='checkbox' value=0 name='<?php echo
I have two checkboxes. I need to check that at least one of them
i'm want to have a repeater generate a bunch of checkboxes, e.g.: <tr><td><input type=checkbox
I have a list of checkboxes, each one with a label: <input type=checkbox id=patient-birth_city
I have the following html code : <form name=uploadForm action= method=POST enctype=multipart/form-data> <input type=file
I have a need to find and manipulate <input type=checkbox> from a table. At
I'm trying to get an object of checkbox names and values. Suppose I have
I have two checkboxes generated like this: <table> <?php foreach ($invited_members as $mem) :

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.