如何从PHP生成的<;选择>;


How to get value from PHP generated <select>?

我有一个包含PHP生成选项的下拉列表。我正在尝试捕获所选的值,因为我需要将其传递给另一个函数。通常情况下,$_POST['patient_dropdown']可以正常工作,但我无法使其适用于我的情况。是否有任何方法可以将所选值捕获到中

<select name="patient_dropdown" id="patient_dropdown" class="patientform">
    <?php 
        $response = "";
        $client = new SoapClient("healthinfosys.wsdl");
        $response = $client->getAllPatientsEntry();
        echo $response;
    ?>
</select>

供您参考,以下是用于生成下拉菜单选项的函数-

function getAllPatientsEntry(){
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "healthinfosys";
    //Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    //Check connection
    if($conn->connect_error){
        die("Connection failed " . $conn->connect_error);
    }

    $sql = "SELECT * FROM patient_info";
    $result = $conn->query($sql);
    if($result->num_rows > 0){
        //Output data of each row
        while($row = $result->fetch_assoc()){
            $output = $output . "<option value='"'">".$row['patient_name']."</option>";
        }
    }
    else{
        echo "0 results";
    }
    $conn->close();
    return $output;
}

您需要为您的选项分配一个值:

    while($row = $result->fetch_assoc()){
        $output = $output.'<option value="'.$row['patient_name'].'">'.$row['patient_name']."</option>";
        // or $row['patient_id'] or something else
    }

您必须为您的选项分配一个值,如下所示您的代码有问题

 //Output data of each row
    while($row = $result->fetch_assoc()){
        $output = $output . "<option value='"'">".$row['patient_name']."</option>";
    }

更改为此

 //Output data of each row
    while($row = $result->fetch_assoc()){
        $output = $output . "<option value='".$row['patient_name']."'>".$row['patient_name']."</option>";
    }