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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:39:40+00:00 2026-06-17T21:39:40+00:00

In short form, users have checkbox values stored in a MySQL database. I can

  • 0

In short form, users have checkbox values stored in a MySQL database. I can loop through the database to display the VALUES (Skills_ID + Skills_Name) for each checkbox so the user can add their skills; however, I’m not able to populate these checkboxes with the default value marked “checked” for those skills already in the database.

A box full of karma for anyone who can help me get to bed tonight. 🙂

Here is my code:

     function isChecked() {
            $query = "select * FROM individual_skills WHERE Ind_ID = ".$_SESSION['Ind_ID']. "";
            $result = mysql_query($query) or die(mysql_error());        
            while($row = mysql_fetch_array($result))
            {
                // If value exists, set $valueExitsInDB to true
                if (isset($row['Skills_ID'])) {
                    $valueExitsInDB="TRUE";
                } else {
                    $valueExitsInDB="FALSE";
                }
                    // if the value does exist, then we are writing 'checked' in the checkbox       
                    if ($valueExitsInDB) {
                        return "checked";
                    } else {
                        return "";
                    }
            } // END WHILE LOOP
        } // END FUNCTION

And, my code within the checkbox loop looks like this (no need to burden you with reading the loop as I can safely pull the checkbox values to the output — just not the default value):

  echo "<input type='checkbox' name='skills[]' value='$skill_ID' checked='isChecked()'>". $skillName ."";

So, you can see, I’m calling the function with: isChecked().

Any, and all help, very much appreciated.

  • 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-17T21:39:42+00:00Added an answer on June 17, 2026 at 9:39 pm

    There are a couple of problems with your code, assuming I understand what you are trying to do:

    • You are not actually calling the function isChecked() as you believe; it is simply the string "isChecked()" being added to the output. If you checked the resulting HTML you would notice this. The line should read:

      echo "<input type='checkbox' name='skills[]' value='$skill_ID'" .
          (isChecked($skill_ID) ? " checked='checked'" : "") . "'> $skillname";
      
    • As you notice above, you should pass the skill ID to the isChecked() function. You should then check this row in the query, not *whether there is any Skills_ID set in the returned query. Otherwise you are checking whether any skill is defined for that individual! So your function should now read:

      function isChecked($skill_ID)
      {
          $query = "SELECT 1 FROM individual_skills WHERE Ind_ID = " . 
              $_SESSION['Ind_ID'] . " AND Skills_ID = $skill_ID";
      
          $result = mysql_query($query) or die(mysql_error());
          return mysql_num_rows($result) = 1;
      }
      

    A couple of side notes:

    • I am returning either a false or true value from the function. This is in line with the naming “is…” which will return a yes or no. The caller (the echo statement) can then decide what to do with the returned value.

    • You probably don’t have to hit the database 1000 times like you are doing now. If you change your initial query to include an isChecked column you won’t need the function and additional queries in the first place.

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

Sidebar

Related Questions

I have a form I'm trying to set up ... Users can have many
I have a checkbox form that lets users select one or more Twitter timelines
I have a web form with about 15 checkboxes that users may check 0
Long story short, I have a form for which I want the id field
I have a new batch form where user can select books from a div
Using Rails 3.1.3. I have Accounts and Users. One Account can have many Users.
I have a django site running with a mysql database backend. I accept fairly
I have a form which allows users to comment on a page, however they
I have a real problem, I can't get sorted out? I have a form
I have an upload form with plupload and a checkbox with boolean value after

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.