• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps app_live server connection using php

sania_06

Lurker
hello there,
i am trying to connect with my server using php, the problem is i am not able to start a new activity when user is verified through a login page.. it shows the response of user is found but it does not open the specified activity.. can some one poitn out the error in the code because there is no run time error...
this is my login.java class
Java:
void login() {
        try {

            httpclient = new DefaultHttpClient();
            httppost = new HttpPost("http://ar-expeditor-android-app.freeiz.com/check.php"); // make sure the url is correct.
            //add your data
            nameValuePairs = new ArrayList<>(2);
            // Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar,
            nameValuePairs.add(new BasicNameValuePair("user_name", user_name.getText().toString().trim()));  // $Edittext_value = $_POST['Edittext_value'];
            nameValuePairs.add(new BasicNameValuePair("password", pass_admin.getText().toString().trim()));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            //Execute HTTP Post Request
            response = httpclient.execute(httppost);
            // edited by James from coderzheaven.. from here....
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            final String response = httpclient.execute(httppost, responseHandler);
            System.out.println("Response : " + response);
            runOnUiThread(new Runnable() {
                public void run() {
                    tv.setText("Response from PHP : " + response);
                    dialog.dismiss();
                }
            });
                 response.trim();
          [B]  if (response.equalsIgnoreCase("congos...User Found... :p ")) {



                        Intent intent = new Intent(Login_admin.this, Insert_images.class);

                        //Toast.makeText(Login_admin.this, "Login Success", Toast.LENGTH_SHORT).show();

                        startActivity(intent);

                    }
[/B]





        } catch (Exception e) {
            dialog.dismiss();
            System.out.println("Exception : " + e.getMessage());
        }
    }

    public void showAlert() {
        Login_admin.this.runOnUiThread(new Runnable() {
            public void run() {
                AlertDialog.Builder builder = new AlertDialog.Builder(Login_admin.this);
                builder.setTitle("Login Error.");
                builder.setMessage("User not Found... =(")
                        .setCancelable(false)
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                            }
                        });
                AlertDialog alert = builder.create();
                alert.show();
            }
my php file...

<?php
$mysql_host = "mysql15.000webhost.com";
$mysql_database = "a9012246_arApp";
$mysql_user = "***mod redacted***";
$mysql_password = "***mod redacted***";
$localhost = mysql_connect($mysql_host,$mysql_user,$mysql_password)
or
trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($mysql_database, $localhost);
$user_name = $_POST['user_name'];
$password = $_POST['password'];
$query_search = "select * from login_admin where user_name = '".$user_name."' 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 "No Such User Found";
}
else  {
  echo "congos...User Found... :p ";
}
?>

        });
    }
 
Last edited by a moderator:
Hello, first things first, its probably not the best idea to post your database username and especially password on a public site like this. Other then that, for HTTP communication to my server I usually use the OkHTTP library, I could walk you through if you'd like.

Let me know.
 
Hello, first things first, its probably not the best idea to post your database username and especially password on a public site like this. Other then that, for HTTP communication to my server I usually use the OkHTTP library, I could walk you through if you'd like.

Let me know.
Great observation, thanks. I redacted them.:thumbsupdroid:
 
Hello, first things first, its probably not the best idea to post your database username and especially password on a public site like this. Other then that, for HTTP communication to my server I usually use the OkHTTP library, I could walk you through if you'd like.

Let me know.
yes, i would like to know about your understanding to it.. because this code is definitely not working for me :/
 
Ok, we can try to set up a time to walk you through it, please send me a message to my inbox on this site, as its most likely going to be better to chat somewhere more efficient then on a forum, going to need to write a lot of code.
 
Back
Top Bottom