Switch from Checkboxes to form text boxes in PHP

advertisements

I'm pretty new to programming and have the following problem. I have a list of 10 movie genres in a form checkbox. The user picks five of their favorite movies and hits submit. Then on the next page the user must rank the 5 movie genres that they selected from 1-5 (1 being their most favorite and 5 being the least). and echo the result in order.

I have the following code for the checkbox page:

<form id="genre" name="genre" method="post" action="picked3.php">
<input type="checkbox" name="moviegenres[]" id="moviegenres" value="Adventure"/>Adventure
<input type="checkbox" name="moviegenres[]" id="moviegenres" value="Animation"/>Animation
<input type="checkbox" name="moviegenres[]" id="moviegenres" value="Biography"/>Biography
<input type="checkbox" name="moviegenres[]" id="moviegenres" value="Classic"/>Classic
<input type="checkbox" name="moviegenres[]" id="moviegenres" value="Comedy"/>Comedy
<input type="checkbox" name="moviegenres[]" id="moviegenres" value="Crime"/>Crime
<input type="checkbox" name="moviegenres[]" id="moviegenres" value="Drama"/>Drama
<input type="checkbox" name="moviegenres[]" id="moviegenres" value="Spy"/>Spy
<input type="checkbox" name="moviegenres[]" id="moviegenres" value="War"/>War
<input type="checkbox" name="moviegenres[]" id="moviegenres" value="Western"/>Western
<input type="submit" value="Submit"></form>

but I need help making the next page with giving the user the ability to rank the genres they have selected from 1-5. I think it can be done with a session function, a for each variable loop for what was checked on the previous page and textboxes to rank from 1-5 but I'm not sure.


Try something like this in your picked3.php. Also remember to check your data.

<?php
        foreach($_POST['genre'] as $item) {
?>
            <div>
                Rank the genre <strong><?php echo $item; ?></strong>

                <select name="<?php echo $item; ?>">
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                </select>
            </div>
<?php
        }
?>