How do I add records to a mysql database using a combo box of text and checkmarks in php?

<h3>Add New Record in MySQL Database</h3>
<form method="post" action="adding.php">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<td width="100">Worker Firstname</td>
<td><input name="firstname" type="text" id="lastname"></td>
<td width="100">Worker Lastname</td>
<td><input name="lastname" type="text" id="lastname"></td>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="1" />Asbestos Awareness
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="1" />Crane Operator
<input name="add" type="submit" id="add" value="Add Worker">

Edited by Dani: Formatting fixed

4 Years
Discussion Span
Last Post by k99rs

All i can see is an array format of checkboxes so that is the code for inserti ng into your database

foreach($name_checkbox as $key)
        //insert query here for the checkbox[]
        echo $key;

Since your using the post method for your form.. In your adding.php file. you can get the values of the elements by using


Since your checkbox is an array.. you just need to used the following code and it will get the array of checkbox.


Now you can create your connection to your database and write your sql statement then execute it. You can read more about ithere

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.