dongxiz5342 2012-01-08 11:22 采纳率: 100%
浏览 71

通过webservice连接

Im trying to insert into a database on a webserver. Im using MYSQL,Appache and 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;

    }

Can someone tell me what im doing wrong here. I keep getting Invalid Code which is Bad Request-400. Help! this is driving me nuts!

  • 写回答

1条回答 默认 最新

  • donglu9825 2012-01-08 11:59
    关注

    If I am reading your php code correctly, it looks to me like your redeemfunction will always hit the sendResponse(400, 'Invalid request'); line at the bottom of the function.

    Is there any case where your redeem function returns true and doesn't send a 400 code back?

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题