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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:50:56+00:00 2026-05-30T12:50:56+00:00

I am trying to get the value from the checkbox selected in a form

  • 0

I am trying to get the value from the checkbox selected in a form inserted into a database using php and sql. I have included the html and some php I am trying to get to work. The first bit of php works great. The second bit of php is one of many attempts to get the value of the checkbox from the form inserted into a database. Thank you for your help!

<?php

$sql = "INSERT into students set student_number = '{$_POST['student_number']}', 
first_name = '{$_POST['first_name']}', last_name = '{$_POST['last_name']}', degree = 
'{$_POST['degree']}'";
mysql_query($sql);

?>

<?php

$classes->bind_result($class);
$classes->execute();
$class = array();
while ($classes->fetch()) {
$class[] = $class;
}

?>
<div class="div1">COP1000:</div><input class="checkbox1" type="checkbox"     
value="COP1000" name="class[]" id="class[]" /><br />

<div class="div1">COP2800:</div><input class="checkbox1" type="checkbox" 
value="COP2800" name="class[]" id="class[]" /><br />

<div class="div1">CIS2910C:</div><input class="checkbox1" type="checkbox"    
value="CIS2910C" name="class[]" id="class[]" /><br />

<div class="div1"> COP2830:</div><input class="checkbox1" type="checkbox"  
value="COP2830" name="class[]" id="class[]" /><br /><br />
  • 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-30T12:50:57+00:00Added an answer on May 30, 2026 at 12:50 pm

    $_POST['class'] is an array.

    You can insert these values into one field your database by (naturally) turn it into a string. The easiest way would be:

    $str = implode(',', $_POST['class']);
    

    which puts a comma (,) between your values. When you want to read all values you can use explode() like this:

    $array = explode(',', $str);
    

    If you wish to loop through every value and perform an update/action on every value, you should loop through the array:

    foreach($_POST['class'] as $class) {
        // run code per class
    
        // example
        $sql = sprintf("INSERT INTO `table` (`class`) VALUES('%s')", mysql_real_escape_string($class));
    }
    

    Important (irrelevant) note: You should sanitize your input before inserting it into your database. If not, users can extend your SQL query and basically can do anything with your database. For more information, click bazmegakapa’s link.

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

Sidebar

Related Questions

I'm trying to get the $url value to display from the MySQL database but
I'm trying to get the selected value from a drop down list via jQuery.
I'm trying to get a value from a netcat connection started at a php
Im trying to grab value from label checkbox:checked. I have created this function var
I am trying to pass a selected checkbox value from one page to another
I'm trying to get the $_POST value from a previous page. <form method=POST> <input
I have a form that I'm trying to get information from the user when
I'm trying to get the onreadystate value from the browser control do detect when
I'm trying to get an RGB value of a pixel from a CGImageRef object.
I am trying to add value to CoreData from .plist and get from coreData

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.