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

Apps user firstname and lastname displayed after successful login

krishnaveni

Well-Known Member
Hi , i need to develop an android application that can do verify userlogin and display a small message if login is successful. When user enters his login details in the app, these login details need to be verified against a sql server DB , and then if the login is successful , i need to display a small message in the app.

So Far I have created a view for login and password. I have a Sql Server on my local machine . In these app , i need the following functionality- Whenever user enters login and password, the Credentials should be verified against existing SqlServer login table , and if login is successful , it should pull out the first name and last name fields for that login record from the table and display it for the user.
 
Classic example of "following a tutorial" but not "understanding the tutorial" or "learning from the tutorial."

Essentially, what you need to do is query the database again (or at the same time you perform the original query, I suppose) for the first name and last name. This is, of course, assuming you have the info in your database and it is properly associated with the correct username/password combo.

Once the query is successful, pass the strings containing the newly obtained first and last names to the next activity via an intent.
 
Krishnaveni, please, don't create so many topics as you are creating, you ask the same thing, but just with another words.

I suggest you begin from the beggining.

Do the google tutorials, don't copy a code and think you can understand it.
 
k thanks for ur rly...i am asked one think...In android how is displayed logged person firstname and lastname after login page success like gmail,yahoo and so on....what method here am used.and how and where is used dis code.give me some solutions.
 
ya i understood ur concepts...am user login page query is

$un=$_POST['login'];
$pw=$_POST['password'];
//connect to the db
$user = 'root';
$pswd = '';
$db = 'xxx';
$conn = mysql_connect('localhost', $user, $pswd);
mysql_select_db($db, $conn);
//run the query to search for the username and password the match
$query = "SELECT firstname,lastname FROM customers WHERE login = '$un' AND password = '$pw' OR usertype ='A'";
$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 1;
}
else
{
echo 0;
}
now how is added my query ...help me some coding part...
 
your PHP isn't setup for JSON. change it to something like this:

Code:
$un=$_POST['login'];
$pw=$_POST['password'];
//connect to the db
$user = 'root';
$pswd = '';
$db = 'xxx';
$conn = mysql_connect('localhost', $user, $pswd);
mysql_select_db($db, $conn);
//run the query to search for the username and password the match
$query = "SELECT firstname,lastname FROM customers WHERE login = '$un' AND password = '$pw' OR usertype ='A'";
$result = mysql_query($query) or die("Unable to verify user because : " . mysql_error());

while($e=mysql_fetch_assoc($result))
	$output[]=$e;

print(json_encode($output));

mysql_close();

after that, in your android application, you would need to do something like so:

Code:
InputStream is = null;
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("login", yourLoginStringHere));
nameValuePairs.add(new BasicNameValuePair("password", yourPasswordStringHere));

try
{
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(ROTM_GET_URL);
	post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
	HttpResponse response = client.execute(post);
	HttpEntity entity = response.getEntity();
	is = entity.getContent();
}
catch(IOException e)
{
//Handle your exception here
}

try
{
	BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);

	StringBuilder sb = new StringBuilder();
	String line = null;

	while((line = reader.readLine()) != null)
		sb.append(line + "\n");

	is.close();

	result = sb.toString();
}
catch(IOException e)
{
        //Handle exception here
}

try
{
	JSONArray jArray = new JSONArray(result);
	for(int i = 0; i < jArray.length(); i++)
	{
		JSONObject json_data = jArray.getJSONObject(i);
                //Do whatever you need with the data here.
	}
}
catch(Exception e)
{
        //Handle excpetions here
}
 
Back
Top Bottom