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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:24:02+00:00 2026-05-28T21:24:02+00:00

I’m trying to use checkboxes to add users to a specific group but I’m

  • 0

I’m trying to use checkboxes to add users to a specific group but I’m having trouble figuring exactly how the logic works. The list of users is pulled from a sql statement and is echo’d. I would like to display a checkbox beside each name, and if the box is checked that user will be added to the list using implode so I can store the members in one column.

Here is the output that displays a list containing users, their location, and a checkbox. I’d like to be able to select the checkbox and then add them to the group based on their userID($friendNum).

Update: the checkboxes are working and properly entering into the databse but the inputs in the first form aren’t being entered. (title, description, date, location)

  $myUsername = $_SESSION['userid'];       
        if(isset($myUsername)){
            echo '<table><form method="post" action="event.php" name="groupInvite"> 
                <tr><td> Event Title:</td><td> <input type="text" name="eventTitle" /></td></tr>
                <tr><td>Event Description:</td><td> <textarea name="eventDescription" /></textarea></td></tr>
                <tr><td>Event Date: </td><td><input type="text" name="eventDate" /></td></tr>
                <tr><td>Event Location:</td><td><input type="text" name="eventLocation" /></td></tr></table>
                <table><tr><td>Username </td><td> Location</td><td>Invite To Event</td></tr>'; 

        $friends = mysql_query("SELECT userid1 as friendId FROM friends WHERE userid2 = $myUsername AND friendstatus = 1
                                UNION SELECT userid2 as friendId FROM friends WHERE userid1 = $myUsername AND friendstatus = 1");

            while($friend = mysql_fetch_array($friends)){
                $userID = $friend['friendId'];
                $friendNum = mysql_query("select * from users where userid = $userID");
                $friendID = mysql_fetch_array($friendNum);
                $userLocation = mysql_query("select * from userinfo where userid='$userID'");
                $locationResult = mysql_fetch_array($userLocation);
                $locationResultArray = $locationResult['userlocation'];
                $locationExplode = explode("~","$locationResultArray");

        echo '<tr>
                <td><a href="profile.php?userid=' . $friendID['userid'] . '">' . $friendID['username'] .  '</a></td>
                <td>' . $locationExplode[0] . ', ' . $locationExplode[1] . '</td>
                <td><input type="checkbox" name="friendID[]" value='.$friendID['userid'].' /></td></tr>';
                }   
            echo '<tr><td> <input type="submit" name="eventSubmit" value="Create Event" />
            </td></tr>
            </form></table>';     
    }   

      if(isset($_POST['eventSubmit'])){
            $userList = implode("~",$_POST['friendID']);
            $sql = "INSERT INTO events VALUES('$userList',...)";  
             $result = mysql_query($sql);   
            echo "Event Created"; //just used for testing purposes
            }  
    }                       
  • 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-28T21:24:02+00:00Added an answer on May 28, 2026 at 9:24 pm

    There are many things wrong with this.

    1. All input elements have to be inside the <form>. i.e., open your form before you start outputting the checkboxes. It might work in some browsers regardless, but not all. I ran into a problem like this recently where only the data in the form would be submitted, but this only occured in Firefox.
    2. Set the value of each checkbox to the friend ID; there’s no need to store it in a hidden element and then try to match it up later. The name of every textbox should be the same with [] appended to it. e.g., <input type="checkbox" value="428" name="friends[]" />. This will cause PHP to organize the $_POST data into an array for you so that you can easily loop over it.
    3. Don’t store all the friend IDs in a single column in the DB. It will make it a nightmare to query later. Use a many-to-many table (Google it if uncertain).
    4. It’s not really an error, but your HTML structure could use some more work too. A better design might look like:

    example:

    <ul>
        <li><label><input type="checkbox" value="428" name="friends[]" /> John Smith</label></li>
        <li><label><input type="checkbox" value="235" name="friends[]" /> Jane Doe</label></li>
    </ul>
    

    The labels will make the checkbox easier to click (can click anywhere on the label), and I believe it makes it easier for screen readers too. A <ul> is more appropriate here semantically, because its a list of friends you’re trying to output.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.