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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:05:42+00:00 2026-05-31T05:05:42+00:00

I am trying to insert the value of this multiple checklist into the db

  • 0

I am trying to insert the value of this multiple checklist into the db column. This code not working. Can anyone spot the problem?

My database consists of a table called “colors” and one column called “color”.

<?php
// connect to database
require "mysql_connect.php";
?>


<?php
// get value from the form
$color = $_POST['color'];

foreach($_POST['color'] as $colors){
$insert = mysql_query("INSERT INTO colors (color) VALUES ('$color')");
}
?>

<form action="add_color.php" method="post" enctype="multipart/form-data" name="colorform"     id="colorform">

<input type="checkbox" name="color[]" value="black" /> Black
<input type="checkbox" name="color[]" value="red" /> Red
<input type="checkbox" name="color[]" value="blue" /> Blue
<input type="checkbox" name="color[]" value="white" /> White

<input name="submit" type="submit" value="Add color" />

</form>

Thanks

  • 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-31T05:05:43+00:00Added an answer on May 31, 2026 at 5:05 am

    This is a nice way to add your colors

    <?php
    
            require "mysql_connect.php";
        // connect to database
        $colors=array();
        // get value from the form
         if (isset($_POST['color']))  $colors = $_POST['color'];
    
        foreach($colors as $color)
        {
            mysql_query ("INSERT INTO colors ('color') VALUES ('$color')");
        }
    ?>
    
    <form action="add_color.php" method="post" enctype="multipart/form-data" name="colorform"     id="colorform">
    
    <input type="checkbox" name="color[]" value="black" /> Black
    <input type="checkbox" name="color[]" value="red" /> Red
    <input type="checkbox" name="color[]" value="blue" /> Blue
    <input type="checkbox" name="color[]" value="white" /> White
    
    <td><input name="submit" type="submit" value="Add color" />
    </form>
    

    if (isset($_POST[‘color’]))
    This condition is important because it will prevent an indexing error in case the array is empty

    $colors=array();
    Also, do declare your variables to prevent getting undeclared varibles, previously, in your code, this will happen if the user does not specify any color

    Remember PHP is server-side and thus getting errors on PHP create loopholes for attacks. Try to read about PHP Best Practices, Its very impotant

    Hopes it helps 🙂

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

Sidebar

Related Questions

This is driving me insane. I'm trying to INSERT a value into the following
I'm trying to insert multiple times this same key into map but with different
This is trying to insert null into Comment.BlogArticleID. The following GenericADOException appeared: could not
im trying to insert this query with mysql_query INSERT INTO um_group_rights (`um_group_id`,`cms_usecase_id`,`um_right_id`) VALUES (2,1,1)
I am trying to insert a value to sql_variant column in sql server from
I am trying to insert an value as '019393' into a table with a
I am trying to insert a row into a table, using a value that
I am trying to figure how to insert a null value into an SQLite
How with SQL server bulk insert can I insert into multiple tables when there
I am trying to insert multiple records into a table where each record has

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.