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

  • Home
  • SEARCH
  • 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 8547375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:15:11+00:00 2026-06-11T13:15:11+00:00

I got a working code on getting the location. I want to store the

  • 0

I got a working code on getting the location.

I want to store the values from a textfield(i just leave it NULL for now), my longitude, latitude and timestamp.

This is the code where i send it to my php file

NSString *latitude =  [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude];
NSString *longitude =  [NSString stringWithFormat:@"%f",   newLocation.coordinate.longitude];
NSString *stringFromDate = [formatter stringFromDate:newLocation.timestamp];


NSMutableURLRequest *request =
[[NSMutableURLRequest alloc] initWithURL:
[NSURL URLWithString:@"http://www.yourdomain.com/locatie.php"]];

[request setHTTPMethod:@"POST"];

NSString* postString = [NSString stringWithFormat:@"%@ %@ %@", latitude, longitude,   stringFromDate];    
[request setValue:[NSString
                   stringWithFormat:@"%d", [postString length]] forHTTPHeaderField:@"Content-length"];

[request setHTTPBody:[postString
                      dataUsingEncoding:NSUTF8StringEncoding]];

[[NSURLConnection alloc] initWithRequest:request delegate:self];

And here’s my code in my PHP File.

<?php
// Connecting, selecting database

$id = $POST['id'];
$longitude = $POST['longitude'];
$latitude = $POST['latitude'];
$timestamp = $POST['stringFromDate'];



$link = mysql_connect('server', 'name', 'pass')
    or die('Could not connect: ' . mysql_error());

mysql_select_db('db_name') or die('Could not select database');

// Performing SQL query
$query("INSERT INTO locatie (id, longitude, latitude, timestamp)
        VALUES (NULL, $longitude,$latitude,$timestamp )");
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

echo "OK";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>

What am i doing wrong?
All the help is appreciated.

Thanks

PS: I don’t get any errors, the only thing is that my database stays empty

It’s still not working, please if anybody knows what i’m doing wrong

  • 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-11T13:15:12+00:00Added an answer on June 11, 2026 at 1:15 pm

    In addition to the other answers about the $_POST global variable, I believe you have 2 PHP errors when you attempt to build your query string.

    1. You aren’t assigning the query string properly to the $query variable. You should use an equal sign to assign the string to the $query PHP variable. For example:

      $query = "INSERT INTO ..."
      
    2. You need to concatenate the PHP variables ($longitude, $latitude, $timestamp) into the query string you are building using a period (.), which is the PHP concatenation operator. The concatenation allows PHP to dynamically build the string.

      $query = "INSERT INTO locatie (id, longitude, latitude, timestamp)
          VALUES (NULL," . $longitude . "," . $latitude . "," .$timestamp." )";
      

    Depending on the format of the $timestamp string and datatypes in your table, you may need to wrap it in single quotes. "'" . $timestamp . "'". Get some sample data for $longtitude, $latitude, $timestamp and try to write the SQL statement in phpMyAdmin or whatever DB tool you are using to see if you need quotes.

    Also, the SQL Injection issue mentioned earlier should also be addressed. You are not sanitizing the strings you assigned to the $longitude, $latitude, $timestamp PHP variables from the $_POST global variable. You’re passing them directly through to MySQL. This is where you can get into trouble if there are malicious statements in the strings.

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

Sidebar

Related Questions

i got this code working and it to return the last tweet from my
Hello I've been expirimenting with the Google Picker API (http://code.google.com/apis/picker/). I've got a working
Got this line of code here but its not working. private void Button_Click(object sender,
I've got the following snippet of code and its all working, and bringing in
EDIT: See end of my post for working code, obtained from zeekay here .
Edit4: I'm happy working in this in Linux now, as I got the rest
So now I'm at least getting callbacks with the following code... - (void)viewDidLoad {
UPDATE: got it working from the commandline after add a full access policy permissions
I've got (working) application done with ttk. It uses self-created module for showing a
At the moment, I've got working: public void logowanie() { int x=5,y=5; ... }

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.