2012-12-26 70 views
1

我在使用$_POST['something'];时遇到PHP问题。如何从两个不同的HTML文本框中获取值?

我有一个HTML身体两个文本框是这样的:

<form method="post"> 
    <div class="style7"> 
     Data Base username 
     <input name="uname" type="text" style="width: 136px" /></div> 
</form> 

<form method="post"> 
    <div class="style7"> 
     Password:<input name="pass" type="password" style="width: 202px" /></div> 
</form> 

我想从这些文本框取值,所以我这样做:

<?php 
    $uname = $_POST['uname']; 
    $pass = $_POST['pass']; 
    echo $pass; 
    echo $uname; 
?> 

当我只把值在第一个文本框中,它只打印第一个文本框。当我仅在第二个文本框中输入一个值时,情况也是如此。但是,当我在同一时间在每个文本框中输入值,然后点击输入时,它只打印第二个值。

有没有办法从两个HTML文本框中使用PHP同时获取值?

回答

6

你需要把它们放在同一<form>

<form method="post"> 
    <div class="style7"> 
     Data Base username 
     <input name="uname" type="text" style="width: 136px" /> 
    </div> 
    <div class="style7"> 
     Password 
     <input name="pass" type="password" style="width: 202px" /> 
    </div> 
</form> 
+0

当我把它们放在相同的形式,然后当我给值(甚至分开),并打入没有任何反应。这就像php脚本不在那里。它只是发出一声小小的嘟嘟声,没有任何其他事情发生:/ – Blenikos

+0

向'

'标签添加一个提交按钮和'action =“yourscript.php”' – ThiefMaster

+0

这样做!非常感谢你!!! :) – Blenikos

相关问题