doutan1637 2014-03-06 08:16
浏览 62
已采纳

如何将ios应用程序中的数据上传到我的sql数据库?

Hi so for my dissertation I'm creating a sports analysis ios app with a website that compliments it. The app does many things but to keep it simple the coach selects the team, and tags any key events e.g tackle, pass etc. The application only shows stats on todays game, but on the website you can see stats from all the games. However I need to find a way to upload those stats

I've found plenty of examples on how to get data from the external database using JSON. However i cant find any example on how to upload data.

I'm using godaddy as my server which hosts my website and sql database.

Any ideas?

  • 写回答

1条回答 默认 最新

  • dqlhsm9820 2014-03-06 10:40
    关注

    Let your server (php file) todo the Hard job iOS side: Use something like that to upload POST your values into the server (php file)

    -(void)upload
    {
        NSString *val1=@"";
        NSString *val2=@"";
        NSString *val3=@"";
    
        NSString *urlString = [NSString stringWithFormat:@"http://domain.com/file.php?value1=%@&value2=%@&value3=%@",val1, val2,val3];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    
    [request setURL:[NSURL URLWithString:urlString]];
    [request setHTTPMethod:@"POST"];
    
    NSMutableData *body= [NSMutableData data];
    
    [request setHTTPBody:body];
    
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:nil];
    
    }
    

    Note: use this returnData if you need get something back after your uploading, like success message or some JSON (whatever you want). Just Parse it to your needs.

    On PHP file:

    <?php
    
    //GET the values from iOS.
    $val1 = $_GET['value1'];
    $val2 = $_GET['value2'];
    $val3 = $_GET['value3'];
    
    
    
    //connect to database
    require 'connect.inc.php';
    
    //just make INSERT SQL Request and done!.
    
    
    ?>
    

    Hope It's Helping you.

    展开全部

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 sql server2008r2索引超出了数组界限
  • ¥15 MATLAB图片转灰度格式问题
  • ¥15 把h5作品链接复制到自己的账号里
  • ¥15 ensp抓包实验配置
  • ¥15 强化学习算法、MRO
  • ¥15 想要学习一门技术来保证以后能够吃上碗饭,该学什么好
  • ¥50 Verilog硬件开发,射频分析求解答
  • ¥20 matlab绘冲床平面连杆机构图和仿真,求帮助
  • ¥15 为什么树莓派5b显示禁止连接
  • ¥15 请专家处理报错!基于深度学习的车型分类问题:数据集为包含 10 种车型的图像数据集,分为训练集、验证集和测试集。
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部