I want to get a selected option from php code below. I keep facing with an error I don't know why I can't get the value.
<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>';
}
?>
Is there other ways to get the selected value?? FYI, I have a class in Cars.php. I don't think you need to care about that. It displays the list by getList() function well.
PLease try this code instead and do advise if it works.
<?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>';
}
?>