Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';无法从PHP获取所选选项_Php - Fatal编程技术网

Can';无法从PHP获取所选选项

Can';无法从PHP获取所选选项,php,Php,我想从下面的php代码中选择一个选项。我一直面临一个错误,我不知道为什么我不能得到这个值 <html> <head> </head> <body> <label>Please select a make below</label> <p></p> </body> </html> <?php include("car

我想从下面的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>';
    }
?>


showInventory.php中有什么内容?将错误报告添加到文件顶部
error\u reporting(E\u ALL);ini设置(“显示错误”,1)在开发中。如果不提交表单,您如何选择选项?抱歉,makeList输入错误