简体   繁体   中英

HTTP post request objective-c

i'm trying to get make a http request to my server and then insert it into mysql table. I do not get any errors. Objective-c returns Connection Successful.

and no errors in php script, but it does not add the rows to mysql server. i've double checked the table and attribute names. How come its not adding to the mysql?

  if (FBSession.activeSession.isOpen) {
        [[FBRequest requestForMe] startWithCompletionHandler:
         ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
             if (!error) {

                NSString *currentId = [user objectForKey:@"id"];
                NSString *currentName = user.name;


                    NSString *post = [NSString stringWithFormat:@"&name=%@&id=%@",currentName,currentId];
                    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

                    NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];

                    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
                    [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.ratemyplays.com/api/post_user.php"]]];

                    [request setHTTPMethod:@"POST"];
                    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
                    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
                    [request setHTTPBody:postData];
                    NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
                    if(conn)
                    {
                            NSLog(@"Connection Successful");
                    }
                    else
                    {
                            NSLog(@"Connection could not be made");
                    }


                }
         }];

php code.

 <?php

 $link = mysqli_connect("mysql12.gigahost.dk","dirts","passwordexample","dirts_api");

 $name = (string)$_POST['name'];
 $id = (int)$_POST['id'];

 mysqli_query($link, "INSERT INTO Users (name, userID) VALUES ('$name', '$id')";


 $result = mysqli_query($link,$query);

 ?>
 $name = (string)$_GET['name'];
 $id = (int)$_GET['id'];

You said POST? then it should be

 $name = (string)$_POST['name'];
 $id = (int)$_POST['id'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM