我在这里有一个小问题。我有一个列表,其中:如何获得用户在php中选择的值?
<form action="display.php" method="post">
<select name="holiday">
<option value="month">Kiekvieno mėnesio skaičiavimas</option>
<option value="day">Kiekvienos dienos skaičiavimas</option>
</select>
<br> <br>
<input type="submit" name="select" value="Pasirinkti" />
</form>
我需要做的是,当用户选择=“一个月”的价值,PHP代码会做一个动作,而当用户选择值=“天”, PHP代码会做另一个动作?
我的PHP代码如下所示:
<?php
if($_POST['select']){
// Storing selected value in a variable
$selectedValue= $_POST['holiday'];
}
else if ($selectedValue == $_POST['month']) {
$todaysDate = new DateTime();
while ($employee = $select->fetch()){
$employmentDateValue = new DateTime($employee['employment_date']);
// Comparing employment date with today's date
$differenceBetweenDates = date_diff($employmentDateValue, $todaysDate);
$workMonths = $differenceBetweenDates->y * 12 + $differenceBetweenDates->m;
$holidayDays = $workMonths *4;
echo "<tr>";
echo "<td>".$employee['name']."</td>";
echo "<td>".$employee['surname']."</td>";
echo "<td>".$employee['employment_date']."</td>";
echo "<td>".$workMonths."</td>";
echo "<td>".$holidayDays."</td>";
echo "</tr>";
}
}
else {
echo "Lalalala";
}
?>
我试着这样做与$ _ POST [“选择”],但它不工作。感谢您的帮助球员
你至少尝试一下这事呢?使用谷歌,我马上得到这个:http://stackoverflow.com/questions/17139501/using-post-to-get-select-option-value-from-html – domsson
可能重复的[使用$ \ _ POST获取选择选项值来自HTML](http://stackoverflow.com/questions/17139501/using-post-to-get-select-option-value-from-html) – domsson