Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8791135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:48:06+00:00 2026-06-13T22:48:06+00:00

I am new to android development. I want to do the login verification, using

  • 0

I am new to android development. I want to do the login verification, using php mysql and json.

I am only taking care of the PHP, MySql and json part.

If the user enters the username and password in android app, then it needs to check the user table using PHP and Mysql and it needs to send only the status code like 1 or 0 using json.

If username and password matches then the status = 1 needs to send to the android app coding, else 0.

Status checking process need to be done in Android Coding part.

If status = 1 and I need to redirect to another window in android app .

I have seen lots of tuts and but nothing has helped me.

So, please kindly help me how to send the status from PHP to android app and how to get that status and validate in android.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:48:07+00:00Added an answer on June 13, 2026 at 10:48 pm

    I have done this code for my project. and it works fine. Give it a try.

    Login2.php

    <?php
    $un=$_POST['username'];
    $pw=$_POST['password'];
    //connect to the db
    
    $host="localhost"; // Host name 
    $user="root"; // Mysql username 
    $pswd=""; // Mysql password 
    $db="database_name"; // Database name 
    $tbl_name="user_info"; // Table name
    
    $conn = mysql_connect($host, $user, $pswd);
    mysql_select_db($db, $conn);
    //run the query to search for the username and password the match
    //$query = "SELECT * FROM $tbl_name WHERE first_name = '$un' AND password = '$pw'";
    $query = "SELECT emp_id FROM $tbl_name WHERE first_name = '$un' AND password = '$pw'";
    $result = mysql_query($query) or die("Unable to verify user because : " . mysql_error());
    //this is where the actual verification happens
    if(mysql_num_rows($result) > 0)
    echo mysql_result($result,0);  // for correct login response
    else
    echo 0; // for incorrect login response
    ?>
    

    Java Code for Android
    login.java

    take two edittext and button and on button click put this code.
    delete saveperference method it you dont want to save username , emp_id to entire application.

        @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
    
                        ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                        postParameters.add(new BasicNameValuePair("username", username
                                .getText().toString()));
                        postParameters.add(new BasicNameValuePair("password", password
                                .getText().toString()));
                        // String valid = "1";
                        String response = null;
                        try {
                            // "http://10.0.2.2//Mobile/login2.php"
                            response = CustomHttpClient
                                    .executeHttpPost(
                                            "http://10.0.2.2//Mobile/login2.php",
                                            postParameters);
    // now in result you will have the response from php file either 0 or 1.                        
    result = response.toString();
                            // res = res.trim();
                            result = result.replaceAll("\\s+", "");
                            // error.setText(res);
    
                            if (!result.equals("0")) {
                                SavePreferences("name", "pass", "emp_id", username
                                        .getText().toString(), password.getText()
                                        .toString());
                                Intent in = new Intent(Login.this, MainScreen.class);
    
                                // LoadPreferences();
                                error.setText("");
    
                                startActivity(in);
                            }
    
                            else
                                error.setText("Incorrect Username or Password");
    
                        } catch (Exception e) {
                            // un.setText(e.toString());
                        }
    
                    }
    

    CustumHttpClient.java

    public class CustomHttpClient {
        /** The time it takes for our client to timeout */
        public static final int HTTP_TIMEOUT = 30 * 1000; // milliseconds
    
        /** Single instance of our HttpClient */
        private static HttpClient mHttpClient;
    
        /**
         * Get our single instance of our HttpClient object.
         *
         * @return an HttpClient object with connection parameters set
         */
        private static HttpClient getHttpClient() {
            if (mHttpClient == null) {
                mHttpClient = new DefaultHttpClient();
                final HttpParams params = mHttpClient.getParams();
                HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
                HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
                ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);
            }
            return mHttpClient;
        }
    
        /**
         * Performs an HTTP Post request to the specified url with the
         * specified parameters.
         *
         * @param url The web address to post the request to
         * @param postParameters The parameters to send via the request
         * @return The result of the request
         * @throws Exception
         */
        public static String executeHttpPost(String url, ArrayList<NameValuePair> postParameters) throws Exception {
            BufferedReader in = null;
            try {
                HttpClient client = getHttpClient();
                HttpPost request = new HttpPost(url);
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
                request.setEntity(formEntity);
                HttpResponse response = client.execute(request);
                in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    
                StringBuffer sb = new StringBuffer("");
                String line = "";
                String NL = System.getProperty("line.separator");
                while ((line = in.readLine()) != null) {
                    sb.append(line + NL);
                }
                in.close();
    
                String result = sb.toString();
                return result;
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    
        /**
         * Performs an HTTP GET request to the specified url.
         *
         * @param url The web address to post the request to
         * @return The result of the request
         * @throws Exception
         */
        public static String executeHttpGet(String url) throws Exception {
            BufferedReader in = null;
            try {
                HttpClient client = getHttpClient();
                HttpGet request = new HttpGet();
                request.setURI(new URI(url));
                HttpResponse response = client.execute(request);
                in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    
                StringBuffer sb = new StringBuffer("");
                String line = "";
                String NL = System.getProperty("line.separator");
                while ((line = in.readLine()) != null) {
                    sb.append(line + NL);
                }
                in.close();
    
                String result = sb.toString();
                return result;
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Android development. I want to show user notification even when
I everyone. I'm very new to Android development and I want to develop an
I am new to android development. I want to make one background application, so
I am new to Android development and I want to learn how to style
I'm new to android development and needs help here.I want to create a layout
I'm new to Android development, so I might be missing something obvious. I want
I am new to Android development and I want to run PING command through
I'm new in Android development but I like it so far. I want to
I am new to Android development using eclipse, although not new to software development
I am very new to android development.... i have created an app and want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.