Looping through Multiple Text Fields
Ok so I am stumped right now. I have two fields that I want to loop through and insert into the db table links. I have initialized a counter but that is as far as I can figure out, that works properlly without errors. Does anyone know of a tutorial that can explain how to do it? I have searched but have not had any luck.
1) Link = Text Field
2) Categories = Select Menu
Form.php
<?php for ($o = 1; $o <= $videofields; $o++) { ?>
<p>
<label for="link<?php echo $o; ?>">Link: <?php echo $o; ?></label>
<input value="<?php if ($_POST && $errors) {
echo htmlentities($_POST["link{$o}"], ENT_COMPAT, 'UTF-8');
}?>" type="text" name="link<?php echo $o; ?>" id="link<?php echo $o; ?>" />
</p>
<p>
<label for="category_id<?php echo $o; ?>">Select Catgegory:</label>
<select name="category_id<?php echo $o; ?>" id="category_id<?php echo $o; ?>">
<option value="0">-- Select place --</option>
<?php
foreach ($categories as $row) {
echo "<option value='{$row['category_id']}'";
if ($errors && $_POST["category_id{$o}"] == $row['category_id']) {
echo 'selected="selected"';
}
echo ">{$row['category_name']}</option>";
}
?>
</select>
</p>
<?php } ?>
Form_Definitions.php
$data = array('link' => $_POST['link'],
'category_id' => $_POST['category_id']);
$dbWrite->insert('videos', $data);
Database Tables
Videos
1. Video_id
2. Link
3. Category_id
Categories
1. Category_id
2. Category_name
Sorry if I am asking for too much. Or not giving enough information. I have been searching but haven't found a solution yet.
Thanks.
