V Mobile
Kamis, 28 Juli 2016
How to send data to mysql from android app
Java
public void insertRecords(String a,String b,String c) { ArrayList
nameValuePairs = new ArrayList
(); nameValuePairs.add(new BasicNameValuePair("a", a)); nameValuePairs.add(new BasicNameValuePair("b",b)); nameValuePairs.add(new BasicNameValuePair("c",c)); sendData(nameValuePairs); } public void sendData(ArrayList
data) { InputStream is=null; try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://10.0.2.2/insert.php"); httppost.setEntity(new UrlEncodedFormEntity(data)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); Log.e("pass 1", "connection success "); } catch(Exception e) { Log.e("Fail 1", e.toString()); Toast.makeText(getApplicationContext(), "Invalid IP Address", Toast.LENGTH_LONG).show(); } String result=""; try { BufferedReader reader = new BufferedReader (new InputStreamReader(is,"iso-8859-1"),8); StringBuilder sb = new StringBuilder(); String line; while ((line = reader.r eadLine()) != null) { sb.append(line + " "); } is.close(); result = sb.toString(); Log.e("pass 2", "connection success "); } catch(Exception e) { Log.e("Fail 2", e.toString()); } }
and call insertRecords(products.get(i).name,products.get(i).price,products.get(i).quantity ) in your button action or where you you want , to add all data
connexion.php
"; echo $e->getMessage(); die(); } ?>
insert.php
add($obj); ?>
class-insert.php
name=$name; $this->price=$price; $this->quantity=$quantity; //_______________________________________________________________ } function add() { global $cnx; $sql="insert into commande values(".$this->name.",".$this->price.",".$this->quantity.")"; if($cnx->exec($sql)) echo" succes:"; else echo"problem"; } } ?>
How to get data from MySQL database to Android app
Tidak ada komentar:
Posting Komentar
Posting Lebih Baru
Posting Lama
Beranda
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar