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

  • SEARCH
  • Home
  • 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 7590449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:24:12+00:00 2026-05-30T20:24:12+00:00

guys i am working on android 2.2 i am stuck where the user need

  • 0

guys i am working on android 2.2 i am stuck where the user need to be authenticated with his use name and password

below is my code

PHP code:

<?php
$un=$_POST['userid'];
$pw=$_POST['password'];

mysql_connect("localhost","root","");
mysql_select_db("myhealthcare");

$sql=mysql_query("select userid,password from register where userid='$un' and password='$pw'");

while($row=mysql_fetch_assoc($sql))

$output[]=$row;

print(json_encode($output));
mysql_close();
?>

Java Code:

ArrayList<NameValuePair> nvp = new  ArrayList<NameValuePair>();

             nvp.add(new BasicNameValuePair("userid", userid.getText().toString()));
             nvp.add(new BasicNameValuePair("password", password.getText().toString()));
             String un = userid.getText().toString();
             String pass = password.getText().toString();

             System.out.println("user name is " + un);
             System.out.println("password is " +pass);
//           Log.e(""+sid.getText().toString(),"0"); 
//           Log.e(""+sname.getText().toString(),"0");
                try {
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://10.0.2.2/login.php");
                httppost.setEntity(new UrlEncodedFormEntity(nvp));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
                } catch(Exception e){
                    Log.e("log_tag", "Error in http connection"+e.toString());
                }
                try {
                    BufferedReader bf  = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                    sb = new StringBuilder();
                    sb.append(bf.readLine()+ "\n");
                    String line="0";
                       while ((line = bf.readLine()) != null) {
                                      sb.append(line + "\n");
                        }
                        is.close();
                        result=sb.toString();
                    System.out.println("value of result " +result);

                }catch(Exception e){
                      Log.e("log_tag", "Error converting result "+e.toString());
                }
                String unm,pwd;
                try {

                    jArray = new JSONArray(result);

                    JSONObject json_data = null;

                    for(int i=0;i<jArray.length();i++){
                         json_data = jArray.getJSONObject(i);
                         unm = json_data.getString("userid");
                         pwd = json_data.getString("password");

                         System.out.println("databse user name  is " +unm);
                         System.out.println("databse password is " +pwd);

                     }

                } catch(JSONException e1){
                      Toast.makeText(getBaseContext(), "No details Found" ,Toast.LENGTH_LONG).show();
                  } catch (ParseException e1) {
                        e1.printStackTrace();
                }

i am able to fetch the value from database but i am not able to compare with user entered values please help

  • 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-05-30T20:24:14+00:00Added an answer on May 30, 2026 at 8:24 pm

    I would do the PHP sometheing like this instead, to do the authentication on the server and not passing the login info back and forth:

    <?php
    $un=mysql_real_escape_string($_POST['userid']);
    $pw=mysql_real_escape_string($_POST['password']);
    
    mysql_connect("localhost","root","");
    mysql_select_db("myhealthcare");
    
    $result=mysql_query("select userid from register where userid='$un' and password='$pw'");
    
    if (mysql_num_rows($result) == 0) {
       print("Not authorized"); // Or send a json-encoded object containing the message
    } else {
       print("Authorized");
    }
    mysql_close();
    ?>
    

    Update

    Use PHP’s mysql_real_escape_string() before running any data input by a user in your SQL. Otherwise you open your DB to SQL-injections, which is really bad.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi guys i am working on an android app where i need to integrate
Hey guys, I'm working on a project. I need to use the function cvFindHomography
guys i am working on android 2.2.I have a situation where when the user
Hello guys I am working on a prolog game and I need to write
Hi guys i am working on drag and drop event in android via jquery
How Guys I'm working on a project that need display same thing like this,
I am now working on an android app in which I need to display
Hi guys I'm in an emergency here. My code was working FINE for a
Hi guys trying to get a 301 redirect working and having trouble. I need
I'm working on developing a native android application to retrieve data for a user

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.