Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 创建登录页面,将数据压缩到sqlite3中_Iphone_Objective C_Cocoa Touch_Sqlite - Fatal编程技术网

Iphone 创建登录页面,将数据压缩到sqlite3中

Iphone 创建登录页面,将数据压缩到sqlite3中,iphone,objective-c,cocoa-touch,sqlite,Iphone,Objective C,Cocoa Touch,Sqlite,我正在尝试在我的应用程序中创建登录页面。为此,我使用的是sqlite数据库(journeymapper.db3是数据库名),它具有UserInformation表 为此,请使用捕禽代码: -(void)checkindatabase { NSString *direct = [[NSString alloc]init] ; NSString *dbPath = [direct stringByAppendingPathComponent:@"journeymapper.db3"]; if(

我正在尝试在我的应用程序中创建登录页面。为此,我使用的是sqlite数据库(journeymapper.db3是数据库名),它具有UserInformation表 为此,请使用捕禽代码:

 -(void)checkindatabase
{
NSString *direct = [[NSString alloc]init] ;
NSString *dbPath = [direct stringByAppendingPathComponent:@"journeymapper.db3"];


if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
{
    NSLog(@"open");
    NSString *sql = [[NSString alloc] initWithFormat:@"select Username='%@',Password='%@' from UserInformation",txtuser.text,txtpass.text];
    //[sql UTF8String];
        //NSLog(@"'%s'",[sql UTF8String]);
    sqlite3_stmt *statment;
    if(sqlite3_prepare_v2(database, [sql UTF8String], -1, &statment, NULL) == SQLITE_OK)
    {
         if(sqlite3_step(statment) == SQLITE_ROW)
         {

             UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil
                                                    message:@"Welcome to joureny" delegate:nil 
                                                   cancelButtonTitle:@"OK" otherButtonTitles:nil];
             [alert show];
             [alert release];  
         }


    }


    sqlite3_finalize(statment);

}
sqlite3_close(database);
}

-(IBAction)login
{
    [self checkindatabase]; 
}

我输入了正确的用户名和密码,但它没有显示alertview如何实现这一点。请帮助我如何创建登录页面。

可能是您的2个任务不正确。1。检查dbpath和查询

一,

二,

将您的查询更改为

NSString *sql = [[NSString alloc] initWithFormat:@"select * from UserInformation where Username='%@' and Password='%@'",txtuser.text,txtpass.text];
如果它返回一些东西…你的用户名和密码是正确的。或者其中一个文本是正确的

编辑的答案

 //To check open DB or not   
 if(open DB)
   //ur code
 else
  NSLog(@"open fails & error is ::%s",sqlite3_errmsg(contactDB));

 // To validate Password    

 if (sqlite3_prepare_v2(contactDB, [sql UTF8String], -1, &statement, NULL) == SQLITE_OK)
  {   if(sqlite3_step(statement) == SQLITE_ROW)
            { 
         //user name is correct
         //if u want to print in log use below code  
         NSString *username=[[NSString alloc] initWithUTF8String:(const char *)       sqlite3_column_text(statement,0)];  
         NSString *password = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement,1)];

            }
       else    
         // Authentication failed
  }

致以最诚挚的问候,

使用这个我想这会对你有所帮助

databasePath = [[NSBundle mainBundle]pathForResource:@"ApplicationData" ofType:@"db"];  
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &adddata) == SQLITE_OK)
{
    NSLog(@"open");


    NSString *querySQL = [NSString stringWithFormat: @"SELECT * FROM login WHERE username=\"%@\" and password=\"%@\"",userNameText.text,passWordText.text];
    NSLog(@"%@",querySQL);

    const char *query_stmt = [querySQL UTF8String];
    sqlite3_stmt *statement;

    int c=sqlite3_prepare_v2(adddata, query_stmt, -1, &statement, NULL); 
    NSLog(@"%d",c);
    if (sqlite3_prepare_v2(adddata, query_stmt, -1, &statement, NULL)==SQLITE_OK)
    {
        if(sqlite3_step(statement)==SQLITE_ROW)
        {


            NewViewController *contacts=[[NewViewController alloc]initWithNibName:@"NewViewController" bundle:nil];
            [self presentModalViewController:contacts animated:YES];
    }

    else 
        {
            alert=[[UIAlertView alloc]initWithTitle:@"alert" message:@"Incorrect username & password" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];
            [alert show];  

            userNameText.text=@"";
            passWordText.text=@"";
        }
    }

    sqlite3_close(adddata);    
}
在.h文件中,您也使用这个

#import "/usr/include/sqlite3.h"
sqlite3 *adddata;
NSString *databasePath;

我认为dbPath应该包含数据库的完整路径,而不仅仅是名称。尝试调试您的数据库已成功打开。它不工作。您可以发送示例代码来解决这个问题吗?一切都很好。在您的代码中,您尝试在成功打开Sqlite DB(journeymapper.db3)后打印打开的日志值。它是否可以成功打开it DB,但如果(Sqlite 3_prepare_v2(数据库,[sql UTF8String],-1,&station,NULL)=Sqlite_OK,则在这种情况下运行执行此操作后,它直接从循环中跳出。它不会检查(sqlite3_步骤(station)==SQLITE_行){我拥有UIAlertView的此条件//当用户权限用户名和密码时}它显示错误:-------------------------------------loginTest[19383:207]从UserName='(null)和Password='(null)的UserInformation中选择*2011-04-05 16:01:17.750 loginTest[19383:207]open这意味着您的用户输入值本身为null。也就是txtser.text,txtpass.text返回null。首先检查UItextfield值为什么为空???
#import "/usr/include/sqlite3.h"
sqlite3 *adddata;
NSString *databasePath;