Я пытаюсь отобразить месяц и соответствующий камень с помощью php. Я использовал ассоциативный массив для динамического заполнения опций для выбора, и я дошел до того, что напечатал камень рождения, но я не могу понять, как получить доступ к именам опций, чтобы отобразить месяц. Это для задания, которое я уже сдал (из которого то, что у меня есть, удовлетворяет требованиям. Я ищу, чтобы выяснить ненужную часть.
Может ли кто-нибудь указать мне правильное направление надоступ к значениям для параметра name = ""
Спасибо!
<html>
<body>
<div>
<h1>Birthstones by Month</h1>
<p>Select a Month from the dropdown to reveal your birthstone</p>
<form action="birthstone.php" method="post">
<?php
$months = array ( 'January' => 'Garnet', 'February' => 'Amethyst', 'March' => 'Aquamarine', 'April' => 'Diamond', 'May' => 'Emerald',
'June' => 'Pearl', 'July' => 'Ruby', 'August' => 'Peridot', 'September' => 'Sapphire', 'October' => 'Tourmaline', 'November' => 'Citrine',
'December' => 'Tanzanite');
print "<select name='bstones'>";
foreach($months as $month => $stone) {
print "print <option value='".$stone ."'name='".$month ."'>" . $month . "</option>";;
}
print "</select> <br />";
?>
<button type="submit" name="sumbit" value="submit">Reveal my Birthstone</button>
</form>
<?php
if (isset($_POST['bstones']))//this is validating the selection
{
$bstones = $_POST['bstones']; //this is assigning a variable name to the option values from the select
print "Your birthstone is <b>$bstones</b>";
}
//I really wanted to display the month selected as well as the stone, but I could not figure out how to get the month to print out. When I try to google this issue,
//I only see instructions on how to access the option value, not the name.
?>
</div>
</body>
</html>