2012-01-08 145 views
0

我試圖插入到Web服務器上的數據庫。即時通訊使用MYSQL,Appache和PHP通過webservice連接

的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; 

    } 

誰能告訴我做什麼我錯在這裏。我一直收到無效的代碼,這是錯誤的請求400。幫幫我!這讓我瘋狂!

回答

0

如果我正確讀取您的php代碼,它看起來像我的redeem函數將始終命中函數底部sendResponse(400, 'Invalid request');行。

是否有任何情況下您的redeem函數返回true,並且不會發送400代碼?

+0

我把它拿出來,但它還沒有經過。我無花果。這是給我一些問題,但我告訴了它,我從這個方法得到一個意想不到的錯誤 - (void)requestFinished:(ASIHTTPRequest *)請求。即時通訊使用IP地址在我的網址導致問題的事實? – user984373 2012-01-08 12:08:25

+0

我怎樣才能確保index.php接收一個值?我可以查詢數據庫以列出所有產品並將其顯示在我的頁面上。那工作找到。似乎index.php頁面沒有在我點擊應用程序上的保存按鈕時收到值。任何方式來檢查這一點? – user984373 2012-01-08 12:14:59

+0

不,使用數字IP地址不是問題。也許你需要從PHP端發回'200'響應,所以你的客戶端的'requestFinished'方法會報告所有的都是成功的? – 2012-01-08 12:17:25