Hello all,
I have been trying to figure this out for the past couple days and can't seem to find the correct solution.
I have two fields:
1) Text field
2) Select Menu (which is pulling selections from db table categories)
categories:
1)category_id
2)category_name
What I want to do is display these fields twice (which I have set up), and be able to post this loop into the db table:
videos:
1)video_id
2)link
3)category_id
Not every post will have a video link associated with it, but some may have a maximum of 2. Here is the code as is for Post.php
<?php for ($i= 1; $i<= $videofields; $i++) { ?>
<p>
<label for="link<?php echo $i; ?>">Video Link<?php echo $i; ?>: </label>
<input value="<?php if ($_POST && $errors) {
echo htmlentities($_POST["link{$i}"], ENT_COMPAT, 'UTF-8');
}?>" type="text" name="link<?php echo $i; ?>" id="link<?php echo $i; ?>" />
</p>
<p>
<label for="category_id<?php echo $i; ?>">Select Catgegory<?php echo $i; ?>:</label>
<select name="category_id<?php echo $i; ?>" id="category_id<?php echo $i; ?>">
<option value="0">-- Select Category --</option>
<?php
foreach ($categories as $row) {
echo "<option value='{$row['category_id']}'";
if ($errors && $_POST["category_id{$i}"] == $row['category_id']) {
echo 'selected="selected"';
}
echo ">{$row['category_name']}</option>";
}
?>
</select>
</p>
And here is the definitons.php
$data = array('link' => $_POST['link'],
'category_id' => $_POST['category_id']);
$dbWrite->insert('videos', $data);
Any help would be greatly appreciated!