我有一个简单的用户名和密码表单,如何将用户输入的值传递到我的php数组中?
我的数组
$post_data = array(
'username' => 'user',
'password' => 'pass#',
);
Form With Array
<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
答案 0 :(得分:2)
输入名称作为键传递给post或get数组:
$_GET['uname'] and $_GET['psw'].
如果您将表单设置为发布(建议用于登录):
<form method = 'POST'>
您可以通过$ _POST superglobal:
访问它们$_POST['uname'] and $_POST['psw'].
所以在你的情况下:
if(isset($_POST['uname']) && isset($_POST['psw']))
{
$post_data = array(
'username' => $_POST['uname'],
'password' => $_POST['psw'],
);
}