Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating a mysql database using php via android
    primarykey
    data
    text
    <p>I am trying to update a mysql database using php from an android application. I have successfully been able to update the database and return data from the database using this tutorial I found here: <a href="http://www.helloandroid.com/tutorials/connecting-mysql-database" rel="nofollow">http://www.helloandroid.com/tutorials/connecting-mysql-database</a></p> <p>I am now trying to update a database using a location provider to obtain the latitude and longitude of a location fix that I am getting via the onLocationChanged callback. My code looks like this:</p> <pre><code>public void onLocationChanged(Location location) { double myLonDouble = location.getLongitude(); String myLon = Double.toString(myLonDouble); double myLatDouble = location.getLatitude(); String myLat = Double.toString(myLatDouble); sp = getSharedPreferences("MyPrefsFile", 0); id = sp.getInt("id", 0); String idString = Integer.toString(id); DatabaseConnector db = new DatabaseConnector(); ArrayList&lt;NameValuePair&gt; latLon = new ArrayList&lt;NameValuePair&gt;(); latLon.add(new BasicNameValuePair("longitude", myLon)); latLon.add(new BasicNameValuePair("latitude", myLat)); latLon.add(new BasicNameValuePair("id", idString)); tv.setText(idString); db.dbConnect(latLon, php); </code></pre> <p>}</p> <p>The method dbConnect, which sends my data to a php file looks like this:</p> <pre><code>public void dbConnect(ArrayList&lt;NameValuePair&gt; data, String phpFile) { InputStream is = null; try{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(phpFile); httppost.setEntity(new UrlEncodedFormEntity(data)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); }catch(Exception e){ Log.e("log_tag", "Error in http connection "+e.toString()); } }// end dbConnect </code></pre> <p>The php file that I am using in the httppost object looks like this:</p> <pre><code>&gt;&gt;&lt;?php &gt;&gt;$con = mysql_connect("localhost","********","*********"); &gt;&gt;if (!$con) &gt;&gt; { &gt;&gt; die('Could not connect: ' . mysql_error()); &gt;&gt; } &gt;&gt; &gt;&gt;mysql_select_db("swizzle_practice", $con); &gt;&gt; &gt;&gt;$_SQL = &gt;&gt;"UPDATE users &gt;&gt;SET longitude = '$_REQUEST[longitude]', latitude = '$_REQUEST[latitude]' &gt;&gt;WHERE id = '$_REQUEST[id]'"; &gt;&gt; &gt;&gt;mysql_query($_SQL,$con) or die("error: " . mysql_error()); &gt;&gt; &gt;&gt;mysql_close($con) &gt;&gt;?&gt; </code></pre> <p>My manifest looks like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.first_screen" android:versionCode="1" android:versionName="1.0"&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt; &lt;uses-sdk android:minSdkVersion="7" /&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;uses-library android:name="com.google.android.maps" /&gt; &lt;activity android:name=".First_screenActivity" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".Setup" android:label="@string/app_name"&gt; &lt;/activity&gt; &lt;activity android:name=".Map" android:label="@string/app_name"&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>I am not getting any errors in the log which leads me to think that it is my code in the dbConnect method that is wrong. I have looked over it and can't seem to find what I am doing wrong.</p> <p>Any help you can give would be much appreciated.</p> <p>Louis</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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