如何将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?

您好我的学位论文正在创建一个体育分析ios应用程序,其中包含一个赞美它的网站。 该应用程序做了很多事情,但为了保持简单,教练选择团队,并标记任何关键事件,例如铲球,传球等。应用程序只显示当今游戏的统计数据,但在网站上你可以看到所有游戏的统计数据。 然而,我需要找到一种上传这些统计数据的方法 p>

我发现了大量关于如何使用JSON从外部数据库获取数据的示例。 但是我无法找到任何关于如何使用JSON的示例 上传数据。 p>

我使用godaddy作为我的服务器来托管我的网站和sql数据库。 p>

有什么想法? p> \ n div>

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.