2012-01-08 32 views
0

ウェブサーバー上のデータベースに挿入しようとしています。 MYSQL、AppacheとPHPウェブサービス経由で接続する

Xcodeの

*-(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が値を受け取っていることを確認する方法はありますか?私はすべての製品をリストし、それを私のページに表示するためにデータベースに問い合わせることができます。それは働くことを見つける。 index.phpのページが私のアプリケーションの保存ボタンを押したときに値を受け取っていないようです。これをチェックする方法はありますか? – user984373

+0

いいえ、数字のIPアドレスを使用しても問題はありません。おそらく、あなたのクライアントの 'requestFinished'メソッドがすべてが成功であったことを報告するように、PHP側から' 200'レスポンスを返す必要がありますか? –

関連する問題