Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To send data to server you could do this:</p> <pre><code>private void sendData(ArrayList&lt;NameValuePair&gt; data) { // 1) Connect via HTTP. 2) Encode data. 3) Send data. try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.blah.com/AddAccelerationData.php"); httppost.setEntity(new UrlEncodedFormEntity(data)); HttpResponse response = httpclient.execute(httppost); Log.i("postData", response.getStatusLine().toString()); //Could do something better with response. } catch(Exception e) { Log.e("log_tag", "Error: "+e.toString()); } } </code></pre> <p>then to send lets say:</p> <pre><code>private void sendAccelerationData(String userIDArg, String dateArg, String timeArg, String timeStamp, String accelX, String accelY, String accelZ) { fileName = "AddAccelerationData.php"; //Add data to be send. ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(7); nameValuePairs.add(new BasicNameValuePair("userID", userIDArg)); nameValuePairs.add(new BasicNameValuePair("date",dateArg)); nameValuePairs.add(new BasicNameValuePair("time",timeArg)); nameValuePairs.add(new BasicNameValuePair("timeStamp",timeStamp)); nameValuePairs.add(new BasicNameValuePair("accelX",accelX)); nameValuePairs.add(new BasicNameValuePair("accelY",accelY)); nameValuePairs.add(new BasicNameValuePair("accelZ",accelZ)); this.sendData(nameValuePairs); } </code></pre> <p>so then the AddAccelerationData.php file on server is:</p> <pre><code>&lt;?php /* * What this file does is it: * 1) Creates connection to database. * 2) Retrieve the data being send. * 3) Add the retrieved data to database 'Data'. * 4) Close database connection. */ require_once '../Connection.php'; //connect to a database/disconnect handler. require_once '../SendAPI.php'; //deals with sending querys. $server = new Connection(); $send = new Send(); //Connect to database. $server-&gt;connectDB(); //Retrieve the data. $userID = $_POST['userID']; $date = $_POST['date']; $time = $_POST['time']; $accelX = $_POST['accelX']; $accelY = $_POST['accelY']; $accelZ = $_POST['accelZ']; //Add data to database 'Data'. //Personal method to query and add to database. $send-&gt;sendAccelerationData($userID, $date, $time, $timeStamp, $accelX, $accelY, $accelZ); //Disconnect from database. $server-&gt;disconnectDB(); ?&gt; </code></pre> <p>This is an example I used recently. Just to note in the php file. I import Connection.php this just deals with the connection to the database. So just replace that with your code for connecting to MYSQL db. Also I imported SendAPI.php (which you can just ignore)This was just my class for sending data. Basically it contained some of the querys I wanted to use. Such as sendAccelerationData(). Basically class was similar to that of stored procedures.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload