Insert data into remote mysql database by POST method from iOS device

后端 未结 3 1288
故里飘歌
故里飘歌 2021-01-14 20:26

I have 3 values :

  • id
  • name
  • email

I have three UIText field where i can give these input and save these values into

3条回答
  •  醉梦人生
    2021-01-14 20:31

    I have a problem updating my database in a similar way....

    Sql statements

    fetch_object())
    {
        // Add each row into our results array
        $tempArray = $row;
        array_push($resultArray, $tempArray);
    }
    
    // Finally, encode the array to JSON and output the results
    echo json_encode($resultArray);
    }
    
    
    $sql = "INSERT INTO table_name (column_name) VALUES('1')";
    
    
    // Close connections
    mysqli_close($result);
    mysqli_close($con);
    ?>
    

    My iOS code

    for (Tickets *items in _feedItems){
        if ([resultText.text isEqual:(id) items.ticketNumber]) {
    
            status.text = @"Match found";
    
     //Contacting database------------------------------
    
            NSString *strURL = [NSString stringWithFormat:@"TicketDate=%@", items.ticketDate];
    
            NSData *postData = [strURL dataUsingEncoding:NSASCIIStringEncoding 
    allowLossyConversion:YES];
            NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
            NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
            [request setURL:[NSURL URLWithString:@"http://webservice.com"]];
            [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");
            }
    
    //Contacting database END-------------------------------------------
    
    
            break;
    
    
        }else {
    
            status.text = @"Match not found";
        }
    }
    

    I get a Connection Succesful from the NSLog but there is nothing getting updated in my database.

    I'm trying to manually type in a ticket number with an app, and if that matches with a ticket in the database (it works), then I want the the ticketDate to change from 0 to 1.

    But it does not change :/

提交回复
热议问题