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 4272186
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:32:37+00:00 2026-05-21T07:32:37+00:00

I am creating an application which first checks whether the user is valid or

  • 0

I am creating an application which first checks whether the user is valid or not by checking data from an SQLite database. I have created a table named loginchk in the database with three rows and two columns in it, uname and pass.

When I run the application and enter the username and password values in my text fields, it checks if the username and password are in the database. If they are not, it will present an alert view that says “Please enter correct username”.

In my code there is a problem: it reads only the first row, i.e., when I enter the username and password values that are in the first row it succeeds, and all the other values that I enter do not work.

What could be the problem?

Thanks.

#import "loginAppDelegate.h"
#import "global.h" 
#import <sqlite3.h>
#import "logincontroller.h" 
@implementation loginAppDelegate 
@synthesize window; 
@synthesize loginView; 
//databaseName=@"login.sqlite";
 -(void) chekAndCreateDatabase 
{   
BOOL success;   
//sqlite3  *databaseName=@"login.sqlite";  
 NSFileManager *fileManager=[NSFileManager defaultManager]; 
 NSArray *documentPaths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);   
NSString *documentsDir =[documentPaths objectAtIndex:0];  
NSString  *databasePath=[documentsDir stringByAppendingPathComponent"login.sqlite"];   success=[fileManager fileExistsAtPathatabasePath];  
 if(success)return;      
NSString *databasePathFromApp=[[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent"login.sqlite"];
      [fileManager copyItemAtPathatabasePathFromApp toPathatabasePath error:nil];   [fileManager release]; 
} 

-(void) Data 
{     
 Gpass=@"";   
Guname=@""; 
sqlite3_stmt *detailStmt=nil;    
//sqlite3  *databaseName;      
NSArray *documentPaths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
NSString *documentsDir =[documentPaths objectAtIndex:0]; 
NSString  *databasePath=[documentsDir stringByAppendingPathComponent{angry_smile}"login.sqlite"];
[self chekAndCreateDatabase];
      sqlite3 *database;   
if (sqlite3_open([databasePath UTF8String],&database)==SQLITE_OK)
 {    
   if (detailStmt==nil)
    {       
      const char *sql= "select *from Loginchk"; //where uname='%?'and password='%?'";       //NSString *sql = [[NSString alloc] initWithFormat{angry_smile}"SELECT * FROM Loginchk WHERE uname ='%@' and password ='%@' ",Uname.text,Password.text];      
 if (sqlite3_prepare_v2(database,sql,-1,&detailStmt,NULL)==SQLITE_OK) 
{                                 
      sqlite3_bind_text(detailStmt,1,[Gunameq UTF8String],-1,SQLITE_TRANSIENT); 
                    sqlite3_bind_text(detailStmt,2,[Gpassq UTF8String],-1,SQLITE_TRANSIENT);                  
if (SQLITE_DONE!= sqlite3_step(detailStmt)) 


{                    
  Guname=[NSString stringWithUTF8Stringchar*)sqlite3_column_text(detailStmt,0)];        

Gpass =[NSString stringWithUTF8Stringchar*)sqlite3_column_text(detailStmt,1)];                    

NSLog(@"'%@'",Guname);         
  NSLog(@"'%@'",Gpass);         }     
  }       sqlite3_finalize(detailStmt);    
 }   
}   sqlite3_close(database); 
  }   

This my login controller; here I am calling my app delegate’s function data:

-(IBAction)buttonPressed:(id)sender 
{     
 Gpassq=Password.text; 
  Gunameq=Uname.text;
      NSLog(@"%@%@",Gunameq,Gpassq);
   loginAppDelegate *appDelegate =(loginAppDelegate *)[[UIApplication sharedApplication]delegate];  
 [appDelegate Data];   
   if ([Uname.text isEqualToString:Guname]&&[Password.text isEqualToString:Gpass])
 {         
 UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"UIAlertView" message:@"Success" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release];
   }     
  else
 {  
    UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"UIAlertView" message:@"PleaseEnterCorrectUserName and password" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
[alert show];      
[alert release];  
  } 
   } 
  • 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-21T07:32:38+00:00Added an answer on May 21, 2026 at 7:32 am

    change

    if (SQLITE_DONE!= sqlite3_step(detailStmt)) 
    

    with

    while  (SQLITE_DONE!= sqlite3_step(detailStmt))
    

    Update 1

    use this code –

    -(void) Data 
    {     
        Gpass=@"";   
        Guname=@""; 
        sqlite3_stmt *detailStmt=nil;    
        //sqlite3  *databaseName;      
        NSArray *documentPaths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
        NSString *documentsDir =[documentPaths objectAtIndex:0]; 
        NSString  *databasePath=[documentsDir stringByAppendingPathComponent:@"login.sqlite"];
        [self chekAndCreateDatabase];
    
    
        sqlite3 *database;   
        if (sqlite3_open([databasePath UTF8String],&database)==SQLITE_OK)
        {    
    
            const char *sql= "select *from Loginchk"; //where uname='%?'and password='%?'";       //NSString *sql = [[NSString alloc] initWithFormat{angry_smile}"SELECT * FROM Loginchk WHERE uname ='%@' and password ='%@' ",Uname.text,Password.text];      
            sqlite3_stmt *detailStmt;   
            if (sqlite3_prepare_v2(database,sql,-1,&detailStmt,NULL)==SQLITE_OK) 
            {                                 
                while(sqlite3_step(detailStmt) == SQLITE_ROW) 
                {
    
                    Guname=[NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt,0)];        
                    Gpass =[NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt,1)];                    
    
                    NSLog(@"'%@'",Guname);         
                    NSLog(@"'%@'",Gpass);         
    
                }     
    
            }   
    
            sqlite3_finalize(detailStmt);    
            sqlite3_close(database); 
    
        }   
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an AIR application which connects to a SQLite database. The database balks
I am creating an application in which I have two mxml components, MainPanel.mxml and
For a web application, when creating the user which will connect to the MySQL
I am creating an Android application which will have some embedded music inside of
I'm creating an application which lets you define events with a time frame. I
I am running creating an iPhone application which performs a costly operation and I
I am creating an application in java which will be the part of an
How can I check whether a message Queue already exists or not? I have
I am creating a music application in which I am adding a scrollview to
Application configuration: Web application using java first method of creating JAX-WS 2.0 Web Services

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.