我在这里获得了选择选项:
<tr>
<td><b>Categoria: </b></td>
<td>
<select style="width: 155px;">
<option value="Desktop">Desktop</option>
<option value="Portatil">Portátil</option>
<option value="Periferico">Periférico</option>
<option value="Tablet">Tablet</option>
</select>
</td>
</tr>
我希望在提交表单时,将选中的值放入php中的变量,就像这个例子一样:
$password=$_POST['password']; /* example of what I'm doing at the beggining of the .php file.
我不知道怎么做。我不知道语法是如何将所选选项带到我想要的变量。
答案 0 :(得分:5)
<select style="width: 155px;" name="device">
<option value="Desktop">Desktop</option>
<option value="Portatil">Portátil</option>
<option value="Periferico">Periférico</option>
<option value="Tablet">Tablet</option>
</select>
为选择字段添加名称,它将以$_POST['device']
答案 1 :(得分:0)
首先插入标记名称, 例如:
<form method="post" action="insert.php">
<input name="txtpassword" type="text" />
<input name="btnsubmit" type="submit" value="Submit" />
</form>
单击按钮时,发送到insert.php文件的数据:
if(isset($_POST["txtpassword"]))
{
....
}
答案 2 :(得分:0)
这里你需要的是:
<?php
//This file is named pageForm.php
if(isset($_POST['action'])
$device = $_POST['device']; //Here your value
}
?>
<form name="myForm" action="pageForm.php" method="post">
<input type="hidden" name="action" value="somethingName">
<select style="width: 155px;" name="device">
<option value="Desktop">Desktop</option>
<option value="Portatil">Portátil</option>
<option value="Periferico">Periférico</option>
<option value="Tablet">Tablet</option>
</select>
<input type="submit" value="Submit">
</form>