2012-01-08 7 views
0

웹 서버의 데이터베이스에 삽입하려고합니다. MYSQL, Appache 및 PHPwebservice를 통해 연결

엑스 코드를 사용하여 임

*-(IBAction)saveRecord:(id)sender{ 
    UITextField *description_txtfield = (UITextField*)[self.tableView viewWithTag:11]; 
    description_string = description_txtfield.text; 
    NSLog(description_string); 

    NSURL *url = [NSURL URLWithString:@"http://192.168.1.140/~admin/qw/"]; 
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 
    [request setPostValue:description_string forKey:@"product_name"]; 
    [request setDelegate:self]; 
    [request startAsynchronous]; 

    [self.navigationController popToRootViewControllerAnimated:YES]; 
} 
- (void)requestFinished:(ASIHTTPRequest *)request {  

    if (request.responseStatusCode == 400) { 
     NSLog(@"Invalid code");   
    } else if (request.responseStatusCode == 403) { 
     NSLog(@"Code already used"); 
    } else if (request.responseStatusCode == 200) { 
     NSLog(@"OK"); 

    } else { 
     NSLog(@"Unexpected error"); 
    } 
    }* 

- (void)requestFailed:(ASIHTTPRequest *)request 
{  
    NSError *error = [request error]; 
    NSLog(error.localizedDescription); 
} 
index.php has the following code inside to handle insert. 

Function redeem() { 

     // Check for required parameters 
     if (isset($_POST["product_name"])) { 

      // Put parameters into local variables 
      $rw_app_id = $_POST["product_name"]; 
      // Add tracking of redemption 
      $stmt = $this->db->prepare("INSERT INTO inventory (product_name) VALUES (?)"); 
      $stmt->bind_param($rw_app_id); 
      $stmt->execute(); 
      $stmt->close(); 

     } 
     return false; 

    } 

누군가 잘못 여기서 뭘 메신저 말해 줄 수. 잘못된 Request-400 인 잘못된 코드가 계속 나타납니다. 도움! 이건 내 견과를 몰고있어!

답변

0

php 코드를 올바르게 읽는다면, 함수의 맨 아래에있는 redeem 함수가 항상 sendResponse(400, 'Invalid request'); 행에 닿는 것처럼 보입니다.

redeem 함수가 true를 반환하고 400 코드를 반환하지 않는 경우가 있습니까?

+0

나는 그것을 꺼내었지만 아직도 진행하지는 않았다. 나는 무화과이다. 그게 나에게 몇 가지 문제를주고 있었지만 나는이 방법으로 예기치 않은 오류가 발생했다는 것을 알았다. - (void) requestFinished : (ASIHTTPRequest *) 요청. 사실 내 URL에 IP 주소를 사용하면 문제가 발생합니까? – user984373

+0

어떻게 index.php가 값을 수신하는지 확인할 수 있습니까? 데이터베이스를 쿼리하여 모든 제품을 나열하고 내 페이지에 표시 할 수 있습니다. thats working find. 내 앱의 저장 버튼을 눌렀을 때 index.php 페이지가 값을 저장하지 않는 것처럼 보입니다. 이것을 체크 아웃 어떤 방법? – user984373

+0

아니요, 숫자 IP 주소를 사용하는 것이 문제가 아닙니다. 클라이언트의'requestFinished' 메소드가 모든 것이 성공이라고보고 할 수 있도록 PHP 측에서'200' 응답을 보내야 할 수도 있습니다. –

관련 문제