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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:30:25+00:00 2026-05-16T06:30:25+00:00

I just want to have php determines whether a checkbox is checked, but I

  • 0

I just want to have php determines whether a checkbox is checked, but I am running into a problem of getting the right return. Help please.

My html code

    <label>
    <input name="Language" type="checkbox" id="aa"  checked="checked"  />
    One</label>
    <label>
    <input name="Language" type="checkbox" id="bb" />Two</label>
    <label>
   <input type="checkbox" name="Language"  id="cc" />Three</label>

I pass the values to php by the $_GET method

my php code:

$aa=$_GET["aa"];
$bb=$_GET["bb"];
$cc=$_GET["cc"];


echo $aa."<br>";
echo $bb."<br>";
echo $cc."<br>";

the output is
true
false
false

I next want to just determine if each box is checked and if so, do something.

if ($aa == true) { $abc="checked";}
else { $abc="not checked"; }

if ($bb == true) { $cde="checked";}
else { $cde="not checked"; }


if ($fgh == true) { $fgh="checked";}
else { $fgh="not checked"; }

But the if statements always return true, even if the box is not checked. I tried variations of “===” and “!=”, but it does not seem to work.

TIA

  • 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-16T06:30:26+00:00Added an answer on May 16, 2026 at 6:30 am
    if (isset($_GET['checkbox_name'])) { ... }
    

    Form controls (with the exception of file inputs, and with some special rules for image inputs) always submit strings. There is no concept of a boolean in a query string or a form encoded POST body.

    The id is irrelevant — only the name and value matter (at least as far as PHP is concerned).

    Since you haven’t given them values they will, IIRC, default to on so if you are doing a comparison you should look for that. Looking with isset is simpler though. This is somewhat beside the point though, since your example gives them all the same name and value, so you can’t differentiate between them.

    Additionally, due to an oddity of the PHP form data parser, you have to end the with [] if you want multiple elements with the same name.

    You probably want to do something like this:

    <label>
    <input name="Language[]" type="checkbox" id="aa"  checked="checked" value="One" />
    One</label>
    <label>
    <input name="Language[]" type="checkbox" id="bb" value="Two" />Two</label>
    <label>
    <input type="checkbox" name="Language[]"  id="cc" value="Three" />Three</label>
    

    Important: Note the addition of values and the change in name.

    Then in PHP $_GET['Language'] will be an Array of the values of the checked checkboxes, which you can loop over.

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

Sidebar

Related Questions

I have a PHP script that is running and I sometimes just want to
I have my index.php page and just afrer my header i want to include
Hi I just want to make sure I have these concepts right. Overloading in
I just want to make sure I'm doing the right thing. I have a
I currently have a php webpage. However, I want to break it down into
I just want to have my anchor in the middle of the screen horizontally,
I just want to have other opinions about this one that I have been
I won't want to have edit any working sets. I just want a way
I have a class that inherits QMainWindow and I just want it to have
I just want what my title says.I have already read all the previous similar

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.