当我使用 php 通过 post 方法获取选择列表的值时,有时该值不会完全显示


When I use php to get the value of a select list using the post method sometimes the value doesn't fully show up

当我使用 post 方法和 php 来处理一个简单的表单时,我尝试回显选择列表选项,但它并没有全部显示,例如我的一个选项是视频卡 $200,当它在卡上回显时,$200 出现在页面上。以下是选择列表:

 <select name="hardware">
 <option>&nbsp;</option>
 <option>Monitor $100</option>
 <option>Mother Board $250</option>
 <option>Video Card $200</option>
 <option>Keyboard $300</option>
 </select>


这是PHP代码

<?php
$parts=$_POST['hardware'];
$partsQuantity=$_POST['hquantity'];
$software=$_POST['software'];
$softwareQuantity=$_POST['squantity'];
echo "".$parts." ".$partsQuantity."<br>".$software." ".$softwareQuantity."<br>";
?>

当我选择视频卡 $200 并回显它时,只显示卡 $200

提交表单时,$_POST['硬件'] 的值将是您在硬件选择中选择的选项的值,而不是选择中包含的所有不同选项的值的列表。此外,您的选项标签都缺少值属性。