[英]Why I can't get the selected function in php/Wordpress to get only one option selected
[英]Can't get the selected option from PHP
我想从下面的PHP代码中获取一个选定的选项。 我一直面对着一个错误,我不知道为什么我无法获得价值。
<html>
<head>
</head>
<body>
<label>Please select a make below</label> <p></p>
</body>
</html>
<?php
include("cars.php");
if (!class_exists("Cars"))
echo"<p>The Cars class is not available!</p>";
else
{
$cars = new Cars();
getList($cars);
echo $_POST["makesList"]; // I thought I could get the selected with this code but it displays the following error "Undefined index: makesList"
}
function getList($cars)
{
$makes = $cars->getMakes();
$makes=array_unique($makes);
echo '<form name="makesForm" id="makesForm" method="POST" action="showInventory.php">';
echo '<select name="makesList" id="makesList">';
foreach($makes as $make)
echo '<option value='.$make.'>'.$make.'</option>';
echo '</select>';
echo '</form>';
}
?>
还有其他方法来获取所选值吗? 仅供参考,我在Cars.php中有一个课程。 我认为您不必关心这一点。 它通过getList()函数很好地显示了列表。
请改用此代码,并建议它是否有效。
<?php
include("cars.php");
if (!class_exists("Cars"))
echo"<p>The Cars class is not available!</p>";
else{
$cars = new Cars();
getList($cars);
echo $_POST["makesList"]; // I thought I could get the selected with this code but it displays the following error "Undefined index: makesList"
}
function getList($cars){
$makes = $cars->getMakes();
$makes=array_unique($makes);
echo '<form name="makesForm" id="makesForm" method="POST" action="showInventory.php">';
echo '<select name="makesList" id="makesList">';
foreach($makes as $make)
echo '<option value='.$make.'>'.$make.'</option>';
echo '</select>';
echo '</form>';
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.