Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9245513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:17:00+00:00 2026-06-18T09:17:00+00:00

So I fixed the question codes with the new code that works and also

  • 0

So I fixed the question codes with the new code that works and also changed the Title of the question for other people to be assist by it.

My problem was that inside the application i’m using in POST method, but on the PHP side, I’m using in GET method. Just changed it to POST and it worked perfectly.

Enjoy.


I keep getting error from my server that the username is wrong, what am I doing wrong here?

Thanks for your help.

- (void)addNewUser:(NSString *)username andDate:(NSDate *)date
{
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

    NSString * urlString = [NSString stringWithFormat:@"http://www.myurl.com/url/insert.php"];
    [request setURL:[NSURL URLWithString:urlString]];
    [request setHTTPMethod:@"POST"];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd-MM-yyyy HH:mm:ss"];
    NSString *strDate = [dateFormatter stringFromDate:date];

    NSString *paramDataString = [NSString stringWithFormat:@"username=%@&date=%@",[username stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
                                 [strDate stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    [request setHTTPBody:[paramDataString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]];

    [NSURLConnection sendAsynchronousRequest:request
                                       queue:[NSOperationQueue mainQueue]
                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                               NSString *requestData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                           }];
}

On the server side I have this: (PHP)

<?php
   header("Content-type: text/html; charset=utf8");

   $connection = mysql_connect("localhost","myusername","mypassword");
   if(!$connection)
   {
       die("database connection failed:" . mysql_error());       
   }

   $db = mysql_select_db("db_users",$connection);
   if(!db)
   {
       die("database connection failed:" . mysql_error());
   }

   mysql_query("SET NAMES 'utf8'",$connection);
?>

<?php 
    $varGet1 = $_POST['username'];
    $varGet2 = $_POST['date'];

    if (!$varGet1) {
        $message = "no username";
    } else if (!$varGet2) {
        $message = "no date";
    } else {
        $query = "INSERT INTO `Users` (username, date, first) VALUES('{$varGet1}','{$varGet2}','0')";

        $query = mysql_query($query,$connection);

        if($query) {
            $message = "Added";
        } else {
            $message = "Error";
        }
    }

    echo($message);

    mysql_close($connection);
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:17:01+00:00Added an answer on June 18, 2026 at 9:17 am

    Nothing is really wrong. You just GET from your php while POSTing from objective-c. Switch to $_POST and you’ll be good to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While Joel Spolsky thinks that every bug should be fixed before new code is
I've seen this code that's been floating around, and also the fixed? version. Basically
Following from these question Subset sum problem and Sum-subset with a fixed subset size
Brief version of my question: This code crashes the compiler. pThread[0] = new boost::thread(
FIXED! The problem was I didn't know you had to initialize a connection to
PROBLEM FIXED FOR NOW. I fixed it by deleting my javascript section for a
How do people switch fixed elements when scrolling down the page? Here's a perfect
I've already found this question on SO (which is exactly the same problem I'm
Yet another SVN guideline question, I know. I recently joined a new company which
I have a PlaceHolder control inside of a ListView that I am using to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.