-3

The php code

$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();

?>

The java code. I get the username and password values from two 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);
    }

So the problem is that I always get null. I want to get the 1 from the response method in PHP.

Zhexa
  • 5
  • 3

1 Answers1

0

The SQL query is using a wrong field. The password field is called 'userPassword', so you query should be

$result=MYSQL_QUERY("SELECT * FROM USER WHERE UserName='$userName' and   userPassword='$userPassword' ");

WARNING: You're storing clear text passwords on your database and this is a really bad practice. You should hash them with a salt

Community
  • 1
  • 1
fjuan
  • 2,214
  • 2
  • 17
  • 20