I'm trying to create something like a breadcrumb based on what is selected from a drop down list. For example if a user selects accessories from a list and then goes on to select from another drop down list scarfs. I want to be able to show:
You selected accessories >> scarfs
somewhere at the bottom of my page. I tried retrieving the selected items using $_POST['item'] and simply printing them with an "echo" but it didn't work. How can this be done? Thanks
Note: The drop down lists are being populated from a database.
This the form code:
<form action="page.php" method = post>
<?php
echo '<select title="Select one" id="categoriesSelect" name="selectcat">';
echo '<option value="default"><?php echo ""?></option>';
while($row1 = $result->fetch_assoc()){
echo '<option value="' . $row1['id'] . '">' . $row1['category'] . '</option>';
}
echo '</select>';
?>
</div>
<?php
echo '<select title="Select one" id="subcatsSelect" name="selectsubcat">';
echo '<option value="default"><?php echo ""?></option>';
while($row2 = $result2->fetch_assoc()){
echo '<option value="' . $row2['subcat'] . '">' . $row2['subcat'] . '</option>';
}
echo '</select>';
?>
</form>
I'm accessing the select boxes in my script(page.php) like this:
if($_SERVER['REQUEST_METHOD'] == 'POST'){
//get data from forms
$cat = $_POST['selectcat'];
$subcat = $_POST['selectsubcat'];
}
I tried to print the selected items like this:
<div class="here">You selected:</div>
<div class="product_directory blue"><a href="#"><?php print $cat?></a></div>
<div class="product_directory arrows">»</div>
<div class="product_directory blue"><a href="#"><?php print $subcat?></a></div>
<div style="margin:0 0 -10px 0;"></div>