LoginPhp.java
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog = ProgressDialog.show(LoginPhp.this, "",
"Validating user...", true);
String username = String.valueOf(et.getText());
String password = String.valueOf(pass.getText());
login(username, password);
}
});
}
void login(String username, String password){
Config config = Config.getInstance();
Log.i("--******------","vghjbkj");
try {
JSON_Parser p = new JSON_Parser();
String url ="http://" + config.getIp() + "/parkinson/check.php?username=" + username + "&password=" + password;
Log.i("---------",url);
JSONObject results = p.readJsonFromUrl(url);
System.out.println(results.toString());
Log.i("--/////////////------",url);
if(!results.has("error"))
{
String result = results.getString("success");
Log.i("--------",result);
if(result.equalsIgnoreCase("true"))
{
Intent intent = new Intent(getApplicationContext(),Menu.class);
startActivity(intent);
finish();
}else{
showAlert();
}
}else{
showAlert();
}
}catch(Exception e )
{
Log.i("erdtrfyguyhbijnk","-------------------------------------ihuiu");
}
}
}
When I go to login it gets stuck on 'Validating user...' I think it has something to do with the Json_Phase class where it says .openSteam()? As wwhen i debug it it wont go past that line..
But I'm not sure how to fix the problem
public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
InputStream is = null;
try {
is = new URL(url).openStream();
BufferedReader rd = new BufferedReader(
new InputStreamReader(is, Charset.forName("UTF-8"))
);
String jsonText = readAll(rd);
Log.i("", jsonText);
JSONObject json = new JSONObject(jsonText);
return (json);
} finally {
if (is != null) {
is.close();
}
}
PHP file
<?php
include('connect.php');
$username = $_GET['username'];
$password = $_GET['password'];
$query_search = "select * from tbl_user where username = '".$username."' AND password = '".$password. "'";
$query_exec = mysql_query($query_search) or die(mysql_error());
$rows = mysql_num_rows($query_exec);
//echo $rows;
if($rows == 0) {
echo '{"success":"false"}';
}
else {
echo '{"success":"true"}';
}
?>