通过webservice连接

时间:2012-01-08 11:22:03

标签: php objective-c web-services ipad nsurl

我试图插入网络服务器上的数据库。我正在使用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;

    }

有人可以告诉我这里我做错了什么。我一直收到错误的代码,这是错误的请求-400。救命!这让我疯了!

1 个答案:

答案 0 :(得分:0)

如果我正确阅读您的PHP代码,我认为您的redeem函数将始终点击函数底部的sendResponse(400, 'Invalid request');行。

是否存在redeem函数返回true且不发送400代码的情况?