Php 在使用while循环时,如何发送提交按钮上下拉选项的值?
我正在使用while循环Php 在使用while循环时,如何发送提交按钮上下拉选项的值?,php,Php,我正在使用while循环 while($work=mysql_fetch_assoc($sql1)){?> <td><?php echo $work['location']; ?></td> <td><form method="post"><select name="title"> <?php while($task=mysql_fetch_assoc($sql2)){?> <opt
while($work=mysql_fetch_assoc($sql1)){?>
<td><?php echo $work['location']; ?></td>
<td><form method="post"><select name="title">
<?php
while($task=mysql_fetch_assoc($sql2)){?>
<option><?php echo $task['title']; ?></option>
<?php }?>
</select></td>
<td><input type="submit" name="submit"><td>
</form>
<?php }?>
while($work=mysql\u fetch\u assoc($sql1)){?>
当我使用以下方式发送$_POST['title']时:
1:header(“location:assign.php?id=$work['id']&title=$\u POST['title'])
2:或使用JS header document.location.href='assign.php?id=$work['id']&title=$\u POST['title']
它只发送“id”而不发送标题
请告诉我如何发送来自下拉列表的标题…您需要为标签指定一个值。
更改此行:
<option><?php echo $task['title']; ?></option>
到
编辑:这是错误的。我没有意识到空值会有默认值/回退。保留答案,这样就不会有人犯同样的错误。“你需要给你的标签一个值”–不,您没有;如果没有明确给出值,选项的内容将自动成为提交值。不知道您在问什么。为我们展示实际问题所在部分的正确代码,而不仅仅是那些没有任何上下文的一行代码。例如,标题行,如果按照您所示,将只生成语法错误。这整本书看起来你应该去阅读如何正确使用字符串。。。
<option value="<?php echo $task['title']; ?>"><?php echo $task['title']; ?></option>