Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old February 3rd, 2012, 07:53 AM   #1 (permalink)
Junior Member
 
Join Date: Dec 2011
Location: chennai
Posts: 61
 
Device(s):
Thanks: 1
Thanked 0 Times in 0 Posts
Default user firstname and lastname displayed after successful login

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.

krishnaveni is offline  
Reply With Quote
Sponsors
Old February 3rd, 2012, 01:36 PM   #2 (permalink)
Senior Member
 
Join Date: Jul 2010
Posts: 977
 
Device(s): Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Thanks: 52
Thanked 199 Times in 144 Posts
Default

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.
jonbonazza is online now  
Reply With Quote
Old February 3rd, 2012, 07:53 PM   #3 (permalink)
Junior Member
 
jonathanrz's Avatar
 
Join Date: Jan 2012
Location: Brazil - Blumenau, SC
Posts: 69
 
Device(s): Motorola Defy - Gingerbread(2.3.3)
Thanks: 12
Thanked 5 Times in 4 Posts
Send a message via MSN to jonathanrz jonathanrafaelz
Default

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.
jonathanrz is offline  
Reply With Quote
Old February 3rd, 2012, 09:44 PM   #4 (permalink)
Junior Member
 
Join Date: Dec 2011
Location: chennai
Posts: 61
 
Device(s):
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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.
krishnaveni is offline  
Reply With Quote
Old February 4th, 2012, 01:00 PM   #5 (permalink)
Senior Member
 
Join Date: Jul 2010
Posts: 977
 
Device(s): Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Thanks: 52
Thanked 199 Times in 144 Posts
Default

I just explained it in my previous reply.
jonbonazza is online now  
Reply With Quote
Old February 6th, 2012, 05:37 AM   #6 (permalink)
Junior Member
 
Join Date: Dec 2011
Location: chennai
Posts: 61
 
Device(s):
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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...
krishnaveni is offline  
Reply With Quote
Old February 6th, 2012, 12:00 PM   #7 (permalink)
Senior Member
 
Join Date: Jul 2010
Posts: 977
 
Device(s): Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Thanks: 52
Thanked 199 Times in 144 Posts
Default

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
}
jonbonazza is online now  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 12:13 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo