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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:22:40+00:00 2026-06-04T19:22:40+00:00

I am creating an admin panel for a project that I am working on.

  • 0

I am creating an admin panel for a project that I am working on. It will list a bunch of entries in a table and each row will have a checkbox in it. This checkbox will be used to activate an entry to be displayed on the website.

I am setting the id and name of the checkbox with data from the MySQL database. For example..

<input type="checkbox" class="active" name="active<?php echo $id; ?>" id="active<?php echo $id; ?>" <?php if ($active == 1): ?>checked="checked"<?php endif; ?> value="<?php echo $id; ?>">

For the entry with ID of 5 it will look like this..

<input type="checkbox" class="active" name="active5" id="active5" checked="checked" value="5">

I need to set this up so that when you check a box or uncheck it that it updates the “active” value in the database. How do I grab the value of each checkbox, when clicked, and send that value to the MySQL database. I can do this easily if I know the checkboxes name beforehand, but since the name is partly generated from the database I’m not sure how to write the code to determine which entry gets the active value.

Here is my jQuery..

$("input.active").click(function() {
// store the values from the form checkbox box, then send via ajax below
var check_active = $(this).is(':checked') ? 1 : 0;
var check_id = $(this).attr('value');

console.log(check_active);
console.log(check_id);

    $.ajax({
        type: "POST",
        url: "http://nowfoods.marketspacecom.com/nextstep/ajax.php",
        data: {id: check_id, active: check_active},
        success: function(){
            $('form#submit').hide(function(){$('div.success').fadeIn();});

        }
    });
return true;
});

Here is the PHP..

<?php

include("dbinfo.inc.php");
mysql_connect($server,$username,$password);
@mysql_select_db($database) or die( "Unable to select database"); 

// CLIENT INFORMATION
$active = mysql_real_escape_string($_POST['active']);
$id = mysql_real_escape_string($_POST['id']);

$addEntry = "UPDATE entries SET active = '$active' WHERE id = '$id'";
mysql_query($addEntry) or die(mysql_error());


mysql_close();

?>

Screenshot of what I am building

  • 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-04T19:22:42+00:00Added an answer on June 4, 2026 at 7:22 pm

    You could add a class to the input and set the value to the id instead:

    <input class="active" type="checkbox" name="active5" id="active5" value="5" checked="checked">

    Then, change your jQuery:

    $("input.active").click(function() {
    // store the values from the form checkbox box, then send via ajax below
    var check_active = $(this).is(':checked') ? 1 : 0;
    var check_id = $(this).attr('value');
    
        $.ajax({
            type: "POST",
            url: "http://nowfoods.marketspacecom.com/nextstep/ajax.php",
            data: {id: check_id, active: check_active}
            success: function(){
                $('form#submit').hide(function(){$('div.success').fadeIn();});
    
            }
        });
    return true;
    });
    

    As for PHP:

    <?php
    
    include("dbinfo.inc.php");
    mysql_connect($server,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database"); 
    
    // CLIENT INFORMATION
    $active        = mysql_real_escape_string($_POST['active']);
    $id = mysql_real_escape_string($_POST['id']);
    
    // WHERE id=16 is just for testing purposes. Need to dynamically find which checkbox was checked and use that info to tell the query which ID to update. 
    $addEntry  = "UPDATE entries SET active = '$active' WHERE id = '$id'";
    mysql_query($addEntry) or die(mysql_error());
    
    mysql_close();
    ?>
    

    This should be what you’re looking for. There may be some minor syntax issues, because I’m writing this off the top of my head, but I hope you get the general idea. 🙂

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

Sidebar

Related Questions

I'm creating a website that will have the admin upload documents available only to
I have a Admin panel(I am creating) with a list of URLs. I would
I am creating a php todo list and have an 'admin_todo' table in a
I have an admin form I'm creating that has four different areas with similar
I'm creating an admin module for my client that gives them access to some
At the moment, I am creating some kind of admin panel/backend for my site.
I am creating an admin menu for a site and I have several drop
I am creating one admin page where I have multiple textboxes.when I enter the
I am creating a website with multiple sections--admin, client, user, and anonymous--each user group
I'm creating an admin tool for a project where I create an Event, then

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.