Can';无法从PHP获取所选选项
我想从下面的php代码中选择一个选项。我一直面临一个错误,我不知道为什么我不能得到这个值Can';无法从PHP获取所选选项,php,Php,我想从下面的php代码中选择一个选项。我一直面临一个错误,我不知道为什么我不能得到这个值 <html> <head> </head> <body> <label>Please select a make below</label> <p></p> </body> </html> <?php include("car
<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>';
}
?>
showInventory.php中有什么内容?将错误报告添加到文件顶部error\u reporting(E\u ALL);ini设置(“显示错误”,1)代码>在开发中。如果不提交表单,您如何选择选项?抱歉,makeList输入错误