0

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>

Edited by Dani: Formatting fixed

3
Contributors
3
Replies
19
Views
3 Years
Discussion Span
Last Post by k99rs
0

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;
    }
?>
0

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

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.