我在同一个表单中需要两个相似的选择选项但是数据库中的两个不同字段都可以修改我的代码。我不需要2个提交按钮,我只是为了更好的可用性而放在那里 我的代码是
echo "
<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">
<p><strong>Event Time (hh:mm):</strong><br/>
<select name=\"event_time_hh\">";
for ($y=1; $y<=24; $y++){
echo "<option value=\"$y\">$y</option>;
<p><strong>Event end (hh:mm):</strong><br/>
<select name=\"event_end_hh\">";
for ($y=1; $y<=24; $y++){
echo "<option value=\"$y\">$y</option>";
}
echo "</select> :
<select name=\"event_end_mm\">
<option value=\"00\">00</option>
<option value=\"15\">15</option>
<option value=\"30\">30</option>
<option value=\"45\">45</option>
<input type=\"submit\" name=\"submit\" value=\"Add Event!\">";
echo "</select> :
<select name=\"event_time_mm\">
<option value=\"00\">00</option>
<option value=\"15\">15</option>
<option value=\"30\">30</option>
<option value=\"45\">45</option>
<input type=\"submit\" name=\"submit\" value=\"Add Event!\">
</form>";
答案 0 :(得分:1)
您的初始代码似乎缺少关闭“select”标记,这可能导致语法错误。
相反,你可以尝试一种更清洁的方法,只在必要时使用PHP(保存转义所有的引号)。
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><strong>Event Time (hh:mm):</strong></p></br />
<select name="event_time_hh">
<?php
for ($y=1; $y<=24; $y++) {
echo "<option value=\"$y\">$y</option>";
}
?>
</select>
<p><strong>Event end (hh:mm):</strong></p></br />
<select name="event_time_hh">
<?php
for ($x=1; $x<=24; $x++) {
echo "<option value=\"$x\">$x</option>";
}
?>
</select>
<select name="event_time_mm">
<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
</select>
<select name="event_end_mm">
<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
</select>
<input type="submit" name="submit" value="Add Event" />
</form>
此外,您可以检查表单是否已提交 - 然后验证并处理输入。
<?php
// Check to see if form has been submitted.
if (isset($_POST['submit'])) {
/* Some validation should be performed here to ensure the following
* values have actually been selected prior to form being submitted.
*/
$event_time_hh = $_POST['event_time_hh'];
$event_time_mm = $_POST['event_time_mm'];
$event_end_hh = $_POST['event_end_hh'];
$event_end_mm = $_POST['event_end_mm'];
}
?>
答案 1 :(得分:0)
这个问题对我来说有点模棱两可。但根据我的理解,你可以做这样的事情
<form action="output.php method="post">
<select name="box1">
// here you populate from db field1
</select>
<select name="box2">
// here you populate from db field2
</select>
<input type="submit" value="submit>
</form>
在output.php中
<?php
$box1 = $_POST['box1'];
$box2 = $_POST['box2'];
?>
答案 2 :(得分:0)
的index.php 回声' “; 为($ Y = 1; $ Y&LT; = 24; $ Y ++) echo“$ y”;
echo '</select>';
echo '
<select name="box2"> ';
for($y=1;$y<=24;$y++)
echo "<option value='$y'>$y</option>";
echo '
</select>
<input type="submit" value="submit">
</form> ';
output.php
$box1_value = $_POST['box1'];
$box2_value = $_POST['box2'];
现在,box1和box2具有2个相应下拉框的选定值。希望它符合您的要求