php代码
$userName=$_POST['userName'];
$userPassword=$_POST['userPassword'];
.
.
$result=MYSQL_QUERY("SELECT * FROM USER WHERE UserName='$userName' and Password='$userPassword' ");
$count=mysql_num_rows($result);
if($count==1){
session_start();
$_SESSION["userName"] = "$userName";
echo 1;
header('Location: http://www.naviwi.com/points.php');
}
else {
header('Location: http://www.naviwi.com/signUp.php');
}
ob_end_flush();
?>
java代码。我从两个TexitEdit IO获取用户名和密码值。
public void userLogin(View view){
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://naviwi.com/checkLogin");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("userName", username));
nameValuePairs.add(new BasicNameValuePair("userPassword", password));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
}catch(UnsupportedEncodingException e){
et.append("UnsupportedEncodingException");
}
try {
response = httpclient.execute(httppost);
}catch (Exception e) {
et.append("Server not Responding"+ response);
}
et.append(" Server respond "+response);
}
所以问题是我总是得到null。我想从PHP中的响应方法中获取1。
答案 0 :(得分:0)
SQL查询使用了错误的字段。密码字段称为“userPassword”,因此您应该查询
$result=MYSQL_QUERY("SELECT * FROM USER WHERE UserName='$userName' and userPassword='$userPassword' ");
警告:您在数据库中存储了明文密码,这是一种非常糟糕的做法。你应该hash them with a salt