【发布时间】:2015-03-31 22:39:15
【问题描述】:
我想从 android 端接收 json 数据。 android端正在将json中的用户名和密码发送到这个php端。 这是我的php代码:
public function actionGetUserLogin()
{
// array for JSON response
$response = array();
$conn=mysqli_connect("localhost","root","","db");
$user_login = "select * from user" ;
$query = mysqli_query ($conn, $user_login);
while($results = mysqli_fetch_array ($query)){
$user_name = $results['mobile_user_name'];
$pass = $results['mobile_user_pass'];
echo $user_name;
echo "</br>";
echo $pass;
echo "</br>";
}
//compare the POST data from user with the existing username and password in database table
if($_POST['username']==$user_name&&$_POST['username']!=""&&$_POST['password']==$pass&&$_POST['password']!="")
{
//if match with database record
$response["success"] = 1;
$response["message"] = "correct";
}else{
$response["success"] = 0;
$response["message"] = "wrong";
}
echo json_encode($response);
Yii::app()->end();
}
当我使用此 url 测试此方法时出现错误:http://localhost/myproject/index.php/user/getuserlogin
错误是:未定义索引:用户名
在接受 json 时我的 php 出现问题了吗? 有没有办法显示android发送的json数据?
【问题讨论】:
-
您必须确保该表单使用 post 方法。