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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:35:26+00:00 2026-06-12T20:35:26+00:00

I have a table of languages from MySQL and in database there is a

  • 0

I have a table of languages from MySQL and in database there is a row “enabled” that has values 1 or 0. 1 for enabled language, 0 for disabled. I would like to change those values with checkboxes in my html/php table.

Problems I encounter are with input names since they are variable from database + values of checked checkboxes.

My code looks like this:

require_once ('../mysqli_connect.php'); // Connect to the db.

if(isset($_POST['submit']))
{
$lang_q="SELECT * FROM language";
$lang_r = @mysqli_query ($dbc, $lang_q); // Run the query.
while($lang_row = mysqli_fetch_array($lang_r, MYSQLI_ASSOC)){
    $lang_code2[]=$lang_row['lang_code'];
    $language[]=$lang_row['language'];
    $langid2[]=$lang_row['lang_id'];
    $lang_active2[]=$lang_row['enabled'];
}
$language2=$_POST[$language];
$lang_active=$_POST[$lang_active2];
$langid=$_POST[$langid2];
$m="test";
if(isset($language2)){
    foreach ($lang_active as $key => $value) {
        $value="1";
    }
    //$lang_active='1';
    $m.="-uspjeh";
}

$q="UPDATE language SET enabled='$lang_active' where lang_id='$langid' ";
$r = @mysqli_query($dbc, $q); // Run the query.
if($r){
    $success=true;
    require_once ('includes/login_functions.inc.php');
    $url = absolute_url();
    $url = absolute_url("language-manager.php?success=update");
    header("Location: $url");
    $m.="-da";
}   
else{
    $s ="<br />GREŠKA UPDATE";
    echo mysqli_error($r);
    $m.="-ne";
}
}
$page_title = PAGE_TITLE84;
include_once('includes/header.php');?>
<?php

$lang_q="SELECT * FROM language";
$lang_r = @mysqli_query ($dbc, $lang_q); // Run the query.
echo $m.'-dadda';
echo '
<form action="language-manager.php" method="POST" name="language-manager">
    <table class="languages">
    <tr>
        <td>'.LANGUAGE_R.'</td>
        <td>'.ACTIVE_R.'</td>
    </tr>
    ';
    while($lang_row = mysqli_fetch_array($lang_r, MYSQLI_ASSOC)){
        $lang_code2=$lang_row['lang_code'];
        $language=$lang_row['language'];
        $lang_active=$lang_row['enabled'];
        $langid=$lang_row['lang_id'];
        echo '<tr>
            <td class="lang"><img src="../flags/'.$lang_code2.'.png" />'.$language.'</td>
            <td>
                <input type="checkbox" name="'.$language.'" id="'.$langid.'" value="'.$lang_active.'"';
                    if($lang_active=='1'){
                        echo ' checked="checked"';
                    }
                echo '>
            </td>
        </tr>';
    }
    echo '</table>
    <input type="submit" name="submit" value="Update" >
</form>
</div>';

mysqli_close($dbc);
  • 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-12T20:35:27+00:00Added an answer on June 12, 2026 at 8:35 pm

    A series of checkboxes in an HTML form all should have the same input name. The server side receives an array by that name. You need to start by making them all the same name. Let’s say you call it ‘enabledLanguages[]’. The ‘[]’ is important, as this is what makes the value send as an array. So you want something more like this:

    <input type="checkbox" name="enabledLanguages[]" id="'.$langid.'" value="'.$lang_active.'"';
                        if($lang_active=='1'){
                            echo ' checked="checked"';
                        }
                    echo '>
    

    Then make the values of each the language id. Change this query:

    $q="UPDATE language SET enabled='$lang_active' where lang_id='$langid' ";
    

    so it’s more like this:

    $langids = implode(',', $_POST['enabledLanguages']);
    // sets each row in this table to 0 (false) if the lang_id isn't IN the $langids list
    // and sets to 1 (true) if it is IN the $langids list
    $q="UPDATE language SET enabled= lang_id IN($langids) > 0";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using SQL Server CE database and C# language. I have a table
I have table with around 70 000 rows. There is 6000 rows that i
I have a few classes, such as those that outline database table structure or
I have a table in mysql having two fileds title_en,title_es If language is ENGLISH
I have a PHP/MySQL based web application that has internationalization support by way of
I have an app that I'm porting from PHP/symfony to Ruby/Rails. Though the language
I have a MySQL database and I am storing user records in the table
I am writing an sms application that retrieves the messages from a MYSQL database
In the interpreter for my experimental programming language I have a symbol table. Each
I have table with 300 000 records (MyISAM). I get record from this table

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.