在php中提交表单时未选择下拉值
该场景是-我有一个具有多个输入字段和文本区域的表单,每当我发布此表单时,所有这些值都将被发布。但是,我也有一个从数据库创建的下拉列表。当我得到这些值时,这个下拉值会正确显示。我有第二个提交按钮,它应该接受这个选择的值并发布到其他页面。 我尝试了$\u POST='name of select option',但没有效果 我有一个onlick用于将表单定向到其他页面以更新数据库。 我对php相当陌生,所以可能是使用了_POST,这可能是不正确的在php中提交表单时未选择下拉值,php,html,forms,post,Php,Html,Forms,Post,该场景是-我有一个具有多个输入字段和文本区域的表单,每当我发布此表单时,所有这些值都将被发布。但是,我也有一个从数据库创建的下拉列表。当我得到这些值时,这个下拉值会正确显示。我有第二个提交按钮,它应该接受这个选择的值并发布到其他页面。 我尝试了$\u POST='name of select option',但没有效果 我有一个onlick用于将表单定向到其他页面以更新数据库。 我对php相当陌生,所以可能是使用了_POST,这可能是不正确的 <form name="f1" class="
<form name="f1" class="formoid-solid-blue" method="GET">
<div class="title">
<h2></h2>
<h2>Tracking & Receiving</h2>
</div>
<div class="element-input">
<label class="title"></label>
<div class="item-cont">
<input class="small" type="text" name="store" placeholder="Store #"/>
<span class="icon-place"></span>
</div>
</div>
<div class="element-input">
<label class="title"></label>
<div class="item-cont">
<input class="medium" type="text" name="userid" placeholder="UserId"/>
<span class="icon-place"></span>
</div>
</div>
<div class="element-input">
<label class="title"></label>
<div class="item-cont">
<input class="large" type="text" name="order" placeholder="Order Number"/>
<span class="icon-place"></span>
</div>
</div>
<div class="submit">
<input type="submit" name="Send" value="Send"/>
</div>
<div class="element-separator">
<hr>
<h3 class="section-break-title">Tracking Numbers</h3>
</div>
<div class="element-multiple">
<label class="title"></label>
<div class="item-cont">
<div class="large">
<select data-no-selected="Nothing selected" name="updTR" multiple="multiple">
<option name="op" value="<?php require 'connection.php'; ?>"> //getting value form db
<?php
echo $trackID; //DB value
$trackID = $_GET['updTR']; //getting the variable from the form
?></option>
</select>
<span class="icon-place"></span>
</div>
</div>
</div>
<div class="submit">
<input type="submit" onclick="f1.action='UpdateTR.php'; return true;" name="UpdateTR" value`enter code here`="Submit"/>
</div>
</form>
好的,看看表单,您说您正在使用POST,并使用其他与POST相关的方法进行了测试,但是您的表单正在使用GET,如上面代码所示 例如,由于您是PHP新手,如果您正在使用post,而另一个页面上有一个变量正在等待从表单中收集此信息,那么您可以这样做:
<?php
while($row = your fetch code here){
echo "<a href='linkHere.php?yourVariableToTrackWithGetHere='".$row['yourDBresutlToTrack']."'> Your text here </a>"; }
?>
这是表单字段示例:
<input type="text" name="XYZ">
现在,如果你想使用GET,那么它是一样的,但是你使用这个
$someVariable = $_GET[ 'XYZ' ];
希望这能消除困惑
-编辑2-
在阅读了您的评论之后,由于我还没有看到您如何在DB中迭代该选项列表/菜单中的选项,我想说,您不能将connection作为此部分的值:
<option name="op" value="<?php require 'connection.php'; ?>">
等等,然后需要php循环遍历数据库结果,并将结果放入该选择中的选项中
下面是一些伪代码:
等等
本质上,您希望while循环在数据库中迭代,并在执行时将其数据输入到options html中
此外,如果您希望从DB中获得一个特定的值,并将其放入GET变量中,以用于处理页面,正如我前面提到的那样,同样,您可以这样做:
<?php
while($row = your fetch code here){
echo "<a href='linkHere.php?yourVariableToTrackWithGetHere='".$row['yourDBresutlToTrack']."'> Your text here </a>"; }
?>
这样,当您单击链接时,数据库值将添加到该变量中,您可以稍后在处理页面中调用该变量
有点啰嗦,但是,这应该会让你100%直截了当。
希望这能有所帮助。谢谢您的解释。正如建议的那样,我使用了上面更新的_GET方法。当我点击submit时,这是发送给UpdateTR.php的url?store=506&userid=TEST&order=9999999244&updTR=&UpdateTR=submit。正如您所看到的,除了下拉菜单-updTR中的值之外,其他所有值都会被拾取。另外,在发送到的页面上,我有以下命令-$updTR=$\u GET['updTR']来收集信息。我的问题是,我提交表单时没有选择值。好的,我想我理解你的问题,嗯,让我找一些代码,因为我最近做了一个这样的项目,但是,它太长了,无法在这里发布,我会很快编辑我的答案
<select>
<?php
while($row = your fetch code here){
echo "<option>your line items here</option>";
}
?>
</select>
<select>
<?php
while($row = your fetch code here){
echo "<option>your line items here "' . $row['some value from DB here'] . '"</option>";
}
?>
</select>
<?php
while($row = your fetch code here){
echo "<a href='linkHere.php?yourVariableToTrackWithGetHere='".$row['yourDBresutlToTrack']."'> Your text here </a>"; }
?>