로그

2014-03-24 4 views
0

임은 사용자가 로그인해야합니다 응용 프로그램을 만들려고. 난 경우 ($ _ POST에 $ 경우 USERCOUNT = 1 개 부분을 변경로그

<?php 
include ("./inc/connect.inc.php"); 
header('Content-type: application/json'); 
if($_POST) { 
$user = 'username'; 
$pass = 'password'; 
$sql = "SELECT * FROM Player WHERE FirstName='$user' AND LastName='$pass'"; 
$userCount = mysql_num_rows($sql); //Count the number of rows returned 
    if ($userCount == 1) { 
    echo '{"success":1}'; 
} else { 
    echo '{"success":0,"error_message":"Username and/or password is invalid."}'; 

} 
}else { echo '{"success":0,"error_message":"Username and/or password is invalid."}'; 

} 

?> 

인 경우 [ 'username'] == 'steffgriff'& & $ _POST [ 'password'] == 'password'). 그런 다음 응용 프로그램 steffgriff와 암호를 입력하면 작동합니다. 왜 그것이 카운트 기능으로 작동하지 않을지 모든 아이디어. 또한

- (IBAction)signinClicked:(id)sender { 
NSInteger success = 0; 
@try { 

    if([[self.txtUsername text] isEqualToString:@""] || [[self.txtPassword text] isEqualToString:@""]) { 

     [self alertStatus:@"Please enter Email and Password" :@"Sign in Failed!" :0]; 

    } else { 
     NSString *post =[[NSString alloc] initWithFormat:@"username=%@&password=%@",[self.txtUsername text],[self.txtPassword text]]; 
     NSLog(@"PostData: %@",post); 

     NSURL *url=[NSURL URLWithString:@"http://www.rugbycoachanalysis.com/jsonlogin.php"]; 

     NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 

     NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]]; 

     NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; 
     [request setURL:url]; 
     [request setHTTPMethod:@"POST"]; 
     [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
     [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; 
     [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
     [request setHTTPBody:postData]; 

     //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]]; 

     NSError *error = [[NSError alloc] init]; 
     NSHTTPURLResponse *response = nil; 
     NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 

     NSLog(@"Response code: %ld", (long)[response statusCode]); 

     if ([response statusCode] >= 200 && [response statusCode] < 300) 
     { 
      NSString *responseData = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding]; 
      NSLog(@"Response ==> %@", responseData); 

      NSError *error = nil; 
      NSDictionary *jsonData = [NSJSONSerialization 
             JSONObjectWithData:urlData 
             options:NSJSONReadingMutableContainers 
             error:&error]; 

      success = [jsonData[@"success"] integerValue]; 
      NSLog(@"Success: %ld",(long)success); 

      if(success == 1) 
      { 
       NSLog(@"Login SUCCESS"); 
      } else { 

       NSString *error_msg = (NSString *) jsonData[@"error_message"]; 
       [self alertStatus:error_msg :@"Sign in Failed!" :0]; 
      } 

     } else { 
      //if (error) NSLog(@"Error: %@", error); 
      [self alertStatus:@"Connection Failed" :@"Sign in Failed!" :0]; 
     } 
    } 
} 
@catch (NSException * e) { 
    NSLog(@"Exception: %@", e); 
    [self alertStatus:@"Sign in Failed." :@"Error!" :0]; 
} 
if (success) { 
    [self performSegueWithIdentifier:@"login_success" sender:self]; 
} 

}

모든 아이디어를 내 응용 프로그램에서 내 코드 아래에 놓을 게요? 감사합니다

답변

0

대신 정적 문자열에서 $user$pass 변수를 설정하는 경우 다음과 같이 $_POST 배열을 검색하려고 :

if($_POST) { 
    $user = $_POST['username']; 
    $pass = $_POST['password']; 
    // Rest of your code 
+0

당신이 새로운 메신저하시기 바랍니다 정교한 수 없습니다. 덕분에 – steff

+0

필요가 없습니다 지금은 고마워요! – steff