DHShah01
DHShah01

Reputation: 551

AFNetworking 2.0 + PHP Simple HTTPRequest


I've tried searching all over the net but couldn't find the answer to specifically my problem. I'm using AFNetworking to send a simple POST HTTP request. The code below results in the following:

 $$da39a3ee5e6b4b0d3255bfef95601890afd8070##!!
 CREATE TABLE $$da39a3ee5e6b4b0d3255bfef95601890afd80709##!! 
 (question VARCHAR(255), answer VARCHAR(255), choices VARCHAR(255), sentBy VARCHAR(255));
 INSERT INTO games (gameId, player1, player2, turn) VALUES ('$$da39a3ee5e6b4b0d3255bfef95601890afd80709##!!', '', '','');

I'm using sha1(), hence the $$da39a3ee5e6b4b0d3255bfef95601890afd80709
Here's my Objective-C code:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *params = @{@"gameId" : datas[0], @"p1": datas[1], @"p2":datas[2], @"turn":datas[3] };
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager POST:@"http://localhost/AnswerThisPHP/newgame.php"
         parameters:params 
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
              NSLog(@"JSON: %@", responseObject);
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"Error: %@", error);
         }];



And my PHP code:

    $db = "db";
    $host = 'host';
    $username = "username";
    $password = 'password';
    $link = mysql_connect($host,$username,$password);
    if (!$link) {
        die('Could not connect: ' . mysql_error());
        echo ("Error - " . mysql_error());
    }
 //Seleccionamos la BBDD
    @mysql_select_db($db);
    //Creamos un array para almacenar los resultados
    $p1 = $_GET['p1'];
    $p2 = $_GET['p2'];
    $gameID = $_GET['gameId'];
    $gameIDSHA = "".$gameID."$$".sha1($gameID)."##".$p1."!!".$p2."";
    $turn = $_GET['turn'];
    $querystring = "CREATE TABLE ".$gameIDSHA." (question VARCHAR(255), answer VARCHAR(255), choices VARCHAR(255), sentBy VARCHAR(255));";
    $querystring2 = "INSERT INTO games (gameId, player1, player2, turn) VALUES ('".$gameIDSHA."', '".$p1."', '".$p2."','".$turn."');";
    echo $gameIDSHA;
    echo '<br/>';
    echo $querystring;
    echo '<br />';
    echo $querystring2;

    $insert = mysql_query($querystring);
    $insert2 = mysql_query($querystring2);

    echo $insert;
    echo $insert2;

Upvotes: 1

Views: 177

Answers (1)

JE Herrejon
JE Herrejon

Reputation: 402

You are sending POST on the client but you are trying to access it trough GET, use $_POST instead of $_GET

Upvotes: 1

Related Questions