我想知道如何从选项标签获取VIA信息,这是我的代码到目前为止,我不知道该怎么做,谢谢。
<html>
<body>
<form method = "post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<select>
<option name = "rock">Rock</option>
<option name = "paper">Paper</option>
<option name = "scissors">Scissors</option>
</select>
<button type = "submit">Submit</button>
</form>
<?php
$rock = $_POST["rock"];
$paper = $_POST["paper"];
$scissors = $_POST["scissors"];
?>
</body>
</html>
答案 0 :(得分:1)
您想要为select命名,并为每个选项设置值,如下所示:
<select name="choice">
<option value= "rock">Rock</option>
<option value= "paper">Paper</option>
<option value= "scissors">Scissors</option>
</select>
和
$pick = $_POST['choice']
另请注意,将操作字段留空会自动回发到同一页面
<form method = "post" action="">