Skip to content Skip to sidebar Skip to footer

Send Data From Android To Php

I need to help about to send data from android to php. I have this java code for android; public void sendToDb() { ArrayList nameValuePairs = new ArrayList

Solution 1:

After reading your comments, what you're trying to do (I think) is persist data. The php file does nothing but run the code you have. The POST variables are only alive if you pass them in the request. The request is coming from the Android app along with POST variables and the response to the Android app will have the correct output.

The request coming from your browser is a "GET" and does not send a pLat or pLng variable, so there is no variables to output.

This is a very basic concept of HTTP that you must grasp.

What you are trying to do is save the data somewhere. PHP can do that by saving it to a database (such as MySQL) or by simply outputting the POST variables to a local file. A quick google search can show you how to save files and open databases. Heck, you can even just send them in an email to yourself.

The PHP script will only hold those variables for the life of the script and then release them out of memory forever. It's up to you to use the power of PHP to save those variables somewhere else.

Solution 2:

At a glance I can already see some insanity here. Why do you specify where username= { $_SESSION['username']} when the call is coming from an android device? What session is there? Additionally, if this fails you insert with no username. but then never run the query.

if (mysql_affected_rows()==0) 
   {
    $query = "INSERT INTO Users ";
    $query .= "(username, lat,lon) VALUES ('ozi', '$pLat','$pLng')";
    mysql_query($query) ordie(mysql_error()); // <---- this would need to be run
   }
 }

I suggest you fix those 2 very critical observations first, then update your question with a more targeted problem. Then I may update this answer to be more useful.

Post a Comment for "Send Data From Android To Php"