2017-04-19 61 views
0

我有一个简单的用户名和密码表单,我如何将通过用户输入的值传递到我的php数组中?将表单值传递到我的PHP数据数组中

我的数组

$post_data = array(
     'username' => 'user', 
     'password' => 'pass#', 
    ); 

形态 - 阵列

<form action=""> 
    <div class=""> 
     <label><b>Username</b></label> 
     <input type="text" placeholder="Enter Username" name="uname" required> 

     <label><b>Password</b></label> 
     <input type="password" placeholder="Enter Password" name="psw" required> 

     <button type="submit">Login</button> 
    </div> 
</form> 
<?php 

session_start(); 

$service_url = 'http://localhost/app/sapi/user/login.xml'; // .xml asks for xml data in response 
$post_data = array(
    'username' => 'user', 
    'password' => 'pass#', 
); 
$post_data = http_build_query($post_data, '', '&'); // Format post data as application/x-www-form-urlencoded 

回答

2

输入名称被作为重点传递到后或得到数组:

$_GET['uname'] and $_GET['psw']. 

如果你设置你的表格发布(这个我的推荐用于登录):

<form method = 'POST'> 

您可以通过$ _POST超全局访问它们:

$_POST['uname'] and $_POST['psw']. 
你的情况

所以:

if(isset($_POST['uname']) && isset($_POST['psw'])) 
{ 
    $post_data = array(
     'username' => $_POST['uname'], 
     'password' => $_POST['psw'], 
    ); 
}