Php HTML仅发布文本表单的最后一个文本框

Php HTML仅发布文本表单的最后一个文本框,php,html,Php,Html,以下是我的HTML代码: <form name="candidates" action="candidate_thankyou.php" method="post"> <div class="wrap"> <div class="position"> President: <br> </div> <input type="text" name="president">

以下是我的HTML代码:

    <form name="candidates" action="candidate_thankyou.php" method="post">
    <div class="wrap"> 
        <div class="position"> President: <br> </div>
            <input type="text" name="president"> <br>
            <input type="text" name="president"> <br>
            <input type="text" name="president"> <br>
    </div>
    <div class="wrap"> 
        <div class="position"> Vice President: <br> </div>
            <input type="text" name="vp"> <br>
            <input type="text" name="vp"> <br>
            <input type="text" name="vp"> <br>
    </div> ...etc
    <input id="submit" type="submit" value="Submit">
    </form>

主席:



副主席:




但是,当我在php文件中调用var_dump($_POST)时,我只得到每个输入名称的最后一个文本框值(例如“president”或“vp”)。如果我只使用前两个文本框,我会得到一个空字符串。如何从表单中获取所有三个值

表单字段由其名称标识。每次您都会覆盖字段
president
/
vp
,这就是为什么您只获取最后一个字段的值。您可以将其作为如下数组发送:

<input type="text" name="president[]"> 
<input type="text" name="president[]"> 
..

..

每个输入都应该有单独的名称,或者在名称末尾添加[]以将它们添加到数组中。即

name="vp[]"

字段名必须是唯一的(
president1
president2
等)或数组
president[]


进一步的处理取决于您选择的方法。第二种方法在

中有详细描述,请显示相关代码。