upload to mysql server not working

I need to add data to my mysql database.However nothing is being added to the actual database below is my xcode and below that is my php code. Can’t seem to see why it doesn’t work? Any suggestions / can you see the error?

-(void) postMessage:(NSString*) teamid withPlayerid:(NSString *) playerid withFixtureid:(NSString *) fixtureid withEventid:(NSString *) eventid withHalfid:(NSString *) halfid{

//check isnt receiving two anit paramters
if(teamid !=nil && playerid !=nil && fixtureid !=nil && eventid !=nil && halfid !=nil){

    NSMutableString *postString = [NSMutableString stringWithString:kPostURL];

    [postString appendString:[NSString stringWithFormat:@"?%@=%@",kTeamid, teamid]];
    //makes kname equal to name
    [postString appendString:[NSString stringWithFormat:@"&%@=%@", kPlayerid , playerid]];

    [postString appendString:[NSString stringWithFormat:@"?%@=%@",kFixtureid, fixtureid]];
    //makes kname equal to name
    [postString appendString:[NSString stringWithFormat:@"&%@=%@", kEventid , eventid]];

    [postString appendString:[NSString stringWithFormat:@"?%@=%@",kHalfid, halfid]];
    //makes kname equal to name

    [postString setString:[postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postString]];
    [request setHTTPMethod:@"POST"];

    postConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];


NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSString
NSString *myString = [prefs stringForKey:@"1 - Prop"];

 _textField3.text = myString;
[self postMessage: self.textField2.text withPlayerid:self.textField3.text withFixtureid:self.textField3.text withEventid:self.textField3.text withHalfid:self.textField3.text];
_textField2.text = nil;
_textField3.text = nil;
dropGoalCounter ++;
[[NSNotificationCenter defaultCenter] postNotificationName:@"DoUpdateLabel" object:nil userInfo:nil];
[self dismissViewControllerAnimated:YES completion:nil];


Here is my php code for inserting into the database

  • Is there a way to programatically restore my iphone to factory settings?
  • Calling function from another ViewController in swift
  • Remove println() for release version iOS Swift
  • No such module Parse using Swift in Xcode 7.1
  • iOS 8: UIAlertView / UIAlertController not showing text or buttons
  • How to open fb and instagram app by tapping on button in Swift
  • <?php
    include ("./inc/connect.inc.php");
    $teamid = (int)$_POST["teamid"];
    $playerid = (int)$_POST["playerid"];
    $fixtureid = (int)$_POST["fixtureid"];
    $eventid = (int)$_POST["eventid"];
    $half = $_POST["halfid"];
    $query = "INSERT INTO MatchEvent (MatchEventID, TeamID, PlayerID,FixtureID,EventID,Half) VALUES ('','9','1','8','7','$half')";
    mysql_query($query) or die(mysql_error("error"));

    This now enters a new entry into the database but all the fields are blank im assuming because of the NSString and in the database the columns are integers. yet when i change the php to this

    $teamid = (int)$_POST["teamid"]
    $playerid = (int)$_POST["playerid"];
    $fixtureid = (int)$_POST["fixtureid"];
    $eventid = (int)$_POST["eventid"];
    $half = (int)$_POST["halfid"];

    It doesnt add an entry to the database at all. Any suggestions?

    3 Solutions Collect From Internet About “upload to mysql server not working”

    Spot the problem:


    [request setHTTPMethod:@"POST"];


    $teamid = $_GET["teamid"];
                ^^^----hmmmmm. not $_POST

    on top of this, you are vulnerable to SQL injection attacks

    include 'connection.php';
    $username = $_POST['username'];
    $password = $_POST['password'];
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $email = $_POST['email'];
    $query = "INSERT INTO Register (username,password,firstname,lastname,email) VALUES   ('$username', '$password', '$firstname', '$lastname', '$email')";

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

    echo $query;

    mine looks like this and works without error

    S[postString appendString:[NSString stringWithFormat:@”?%@=%@”,kHalfid, halfid]]; has a ? instead of &.