1

此表单包含许多其他工作正常的输入,就像<input>, <select> (not multiple) etc...我在使用<select multiple. 我有以下代码:

<form action="phpaction.php" method="post">
<select name="states[]" multiple>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
...
</select>

// phpaction.php file
$statesArray=$_POST['states'];
print_r ($statesArray);

为什么它不工作?我收到以下错误:Undefined index: states in phpaction.php on line 72

4

1 回答 1

3

尝试这个:

<?php
if ($_SERVER['REQUEST_METHOD']==='POST') {
    $statesArray=$_POST['states'];
    print_r($statesArray);
}
?>

<form action="" method="post">
    <select name="states[]" multiple>
        <option value="AL">Alabama</option>
        <option value="AK">Alaska</option>
    </select>
    <input type="submit">
</form>
于 2013-05-12T01:52:39.190 回答