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

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

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

<?php
foreach($name_checkbox as $key)
    {   
        //insert query here for the checkbox[]
        echo $key;
    }
?>

yeah I get that but how

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

$_POST['nameOfYourElement']

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

$_POST['checkbox']

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.