How can dynamic input forms be created in PHP to allow users to select multiple options and store them in a database?
To create dynamic input forms in PHP for users to select multiple options and store them in a database, you can use HTML form elements with the "multiple" attribute for select boxes or checkboxes. Upon form submission, you can process the selected options using PHP and insert them into the database accordingly.
<form method="post" action="process_form.php">
<select name="options[]" multiple>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select>
<input type="submit" value="Submit">
</form>
<?php
// process_form.php
$options = $_POST['options'];
// Insert selected options into the database
foreach($options as $option) {
// Insert $option into the database using SQL query
}
?>