Using mySQL & Php in Android -
im trying add values mysql database android application here php file :
<?php $connection = mysql_connect("mywebhost.example", "user", "password")ordie(mysql_error()); $selection = mysql_select_db("name_of_database", $connection)or die(mysql_error()); $name = $_post['name']; $points = $_post['points']; $insert = "insert my_table('name','points') values('$name','$points')"; $run = mysql_query($insert)or die(mysql_error()); ?>
and here android code :
public void test_button (view view) { new netsd().execute(); } class netsd extends asynctask<string,string,string> { @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(mainactivity.this); pdialog.setmessage("loading . please wait..."); pdialog.setindeterminate(false); pdialog.setcancelable(false); pdialog.show(); } @override protected string doinbackground(string... params) { // todo auto-generated method stub list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(); namevaluepairs.add(new basicnamevaluepair("country", country)); namevaluepairs.add(new basicnamevaluepair("points", integer.tostring(points))); try { defaulthttpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost("http://heremyexampel.com/android_connect.php"); httppost.setentity(new urlencodedformentity(namevaluepairs)); httpresponse httpresponse = httpclient.execute(httppost); httpentity httpentity = httpresponse.getentity(); } catch (unsupportedencodingexception e) { e.printstacktrace(); } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } return null; } protected void onpostexecute(string file_url) { pdialog.cancel(); } }
i dont problems in eclipse there no values in mysql.so hes not adding them... tried asynctask dont well...
<string,string,string>
is because of ? thank ! (of course passwort server link etc example)
Comments
Post a Comment