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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:46:55+00:00 2026-06-08T17:46:55+00:00

I have a list of checkboxes and save the checked values in an array.

  • 0

I have a list of checkboxes and save the checked values in an array. However, when someone clicks ‘submit’ and they get an error, all their checked boxes are forgotten. Usually I would let the script remember the checked boxes with a code like

IF checkbox value = OK { echo checked=”checked”}

However, now I save it in an array and I have no idea how to do this?

<?php

$sql = "SELECT merknaam FROM merken";
$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
    echo "&nbsp;&nbsp;<input type=\"checkbox\" name=\"merken[]\" value='" . $row['merknaam'] . "'>&nbsp;" . $row['merknaam'] . " <Br />  ";
}

?>

This is the code I use for the checkboxes. Next I display the array with this code:

$merkenstring = implode(",", $_POST['merken']);

echo $merkenstring;

Result: AC Ryan,Adidas,Agu,Cargo

I hope someone could give me a code example!

  • 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-08T17:46:56+00:00Added an answer on June 8, 2026 at 5:46 pm

    Assuming you are posting this to the same page, and $_POST['merken'] is still available after an error, use in_array() to test each checkbox’s value against the current set in $_POST:

    while ($row = mysql_fetch_array($result)) {
        // If the current value is in the $_POST['merken'] array
        // and the array has been initialized...
        if (isset($_POST['merken']) && is_array($_POST['merken']) && in_array($row['merknaam'], $_POST['merken'])) {
          // Set the $checked string
          $checked = "checked='checked'";
        }
        // Otherwise $checked is an empty string
        else $checked = "";
        // And incorporate it into your <input> tag
        echo "&nbsp;&nbsp;<input $checked type=\"checkbox\" name=\"merken[]\" value='" . $row['merknaam'] . "'>&nbsp;" . $row['merknaam'] . " <Br />  ";
        //----------------------^^^^^^^^^^
    }
    

    If this was posted to a different script, you would (as with any post value returned to a previous script) need to store the array in $_SESSION instead and compare against $_SESSION['merken'] in your in_array() call.

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

Sidebar

Related Questions

I have a list of Checkboxes & I want to get the status of
i have used a checkbox list in my project .am storing all the checked
I have a list with corresponding checkboxes, I would like to save the state
I currently have a list of checkboxes all with the same ID which are
I have a mysql/php generated list of checkboxes, all assigned to admins of the
I have a list of checkboxes like you would see in most email clients
I have a list of checkboxes in a table like this along with a
I have this long list of checkboxes with specific labels that look something like
I have this long list of checkboxes with specific labels that look something like
Basically, I have a list of delivery checkboxes one for deliver to this address

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.