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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:06:38+00:00 2026-05-25T21:06:38+00:00

How to Insert update and delete checkbox datas in mysql database table.I need mysql

  • 0

How to Insert update and delete checkbox datas in mysql database table.I need mysql query for all operations . I have only one database table for that operations. Thanks in advance

<input type="checkbox" name="sports" value="Cricket" /> Cricket 
<input type="checkbox" name="sports" value="Football" />Football 
<input type="checkbox" name="sports" value="Chess" />Chess 

Database Structure

ID ,NAME, AGE ,SPORTS(checkbox need to save)
  • 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-25T21:06:39+00:00Added an answer on May 25, 2026 at 9:06 pm

    Like Shef said, you need those 3 tables user, sport, user_sport

    user

    +----+----------------+-----+
    | id | name           | age |
    +----+----------------+-----+
    |  1 | Freddy Mercury |  65 |
    |  2 | Ian Gillan     |  66 |
    |  . | .              |   . |
    +----+----------------+-----+
    

    sport

    +----+----------+
    | id | sport    |
    +----+----------+
    |  1 | Cricket  |
    |  2 | Football |
    |  3 | Chess    |
    +----+----------+
    

    user_sport

    +---------+----------+
    | user_id | sport_id |
    +---------+----------+
    |       . |        . |
    +---------+----------+
    

    Generate the checkboxes with this php:

    $sql = '/* Current User Sports */
    SELECT
      sp.id AS "sport_id"
    , sp.name As "sport"
    , us.user_id AS "checked"
    FROM sport AS sp
    LEFT JOIN user_sport AS us ON (
      sp.id = us.sport_id
      AND user_id = '.$user_id.'
    )
    ;';
    $result = query($sql);
    foreach ($result as $row) {
    ?>
      <label>
        <input type="checkbox" name="sports[<?php echo ($row['sport_id']) ?>]" checked="checked" />
        <?php echo ($row['sport']) ?>
      </label>
    <?php
    }
    

    That will give you this HTML:

    <input type="checkbox" name="sports[1]" checked="checked" />Cricket 
    <input type="checkbox" name="sports[2]" checked="checked" />Football 
    <input type="checkbox" name="sports[3]" checked="checked" />Chess 
    

    The update part

    First query (Delete the values for the current $user_id):

    DELETE FROM user_sport WHERE user_id = $user_id;
    

    Second query (Insert the new values for the current $user_id):

    $sql = 'INSERT INTO user_sport
      (user_id, sport_id)
    VALUES
      (';
    $tmp = array();
    foreach ($sports as $sport_id => $void) {
      $tmp[] = "($user_id, $sport_id)"
    }
    $sql .= implode("\n,   ", $tmp).'
      )
    ;';
    

    This can work for insert/update/delete

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

Sidebar

Related Questions

I want to have an 'updateinfo' table in order to record every update/insert/delete operations
Merge can performs insert, update, or delete operations on a target table based on
I tried to create a database by the following command: mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,ALTER,INDEX,DROP, ->
After performing an insert/update/delete, is it necessary to query the database to check if
Currently I have some event listeners setup to log all insert/update/delete actions that happen.
I need a quick no for DELETE/UPDATE/INSERT, since 3p reporting tool allows users to
SQLite3::SQLException: SQL logic error or missing database error when do insert, update and delete
How does INSERT, UPDATE & DELETE work on a SQL Server table partition? Technical
a) SqlCommand.ExecuteNonQuery is used for update, insert and delete operations. Besides the fact that
i saw this In MySQL, joins work for INSERT, UPDATE, and DELETE statements. It's

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.