passing Edit text data from android to php -
I need to read data from an external database with hundreds of items. I have done so far that I wrote php query Which returns all the items, so I
php:
$ db_host = "host"; $ Db_uid = "username"; $ Db_pass = "password"; $ Db_name = "person"; $ Db_con = mysql_connect ($ db_host, $ db_uid, $ db_pass) or die ('Could not connect'); Mysql_select_db ($ db_name); $ Sql = "Select from the employee"; $ Result = mysql_query ($ sql); While ($ line = mysql_fetch_assoc ($ result)) $ output [] = $ line; Print (json_encode ($ production)); Mysql_close (); Android:
string URL = "http: //localhost/index.php"; Public Zero OnCreate (Bundle savedInstanceState) @Override {/ * * StrictMode is used to catch the most casual disk or network * Main thread of application * / StrictMode.setThreadPolicy (New StrictMode.ThreadPolicy.Builder () .detectDiskReads ( ). DetectDiskWrites (). DetectNetwork () .penaltyLog (). Build ()); Super.onCreate (savedInstanceState); SetContentView (R.layout.hospital); Byear = (EditText) findViewById (R.id.editText1); Submit = (button) Find VVBIID (RID: SubmitButtons); Tv = (TextView) findViewById (R.id.showresult); When the user clicks on the submit submit button. SetOnClickListener // Set the task (New View. OnClickListener) {Public Zero onClick (see v) {// Declared parameter ie // name "birthyear" are passed to PHP scripts And its value user ArrayList & lt; NameValuePair & gt; postParameters = new ArrayList & lt; NameValuePair & gt; ();. Data = byear.getText () toString (); // parameter postParameters.add (New BasicNameValuePair (" Data ", data)); string response = null; // execute execution of HTTP executing method required Try the parameter {response = CustomHttpClient.executeHttpPost (url, postParameters); // result that returns the // mysql query string result that is given by php script = response.toString () store; // parse json data try {returnString = "" ; JSONArray jArray = New JSONArray (results); {JSONObject json_data = jArray.getJSONObject (i); Log.i ("log_tag") for {i.e. + i & lt; jArray.length (); i ++) , "Id:" + json_data.getInt ("id") + ", name:" + json_data.getString ("name")); // receive the screen return string + "\ n" + "name =" + json_data.getString ("name") + "\ n" + "contact number =" + json_data.getInt ("contact") + "\ An output for n "}} hold (JasonXEpisode E) {Log.e (" log_tag "," error parsing data "+ E.Streatin ()); } Try {Tv.setText (returnString); } Hold (exception e) {Log.e ("log_tag", "error in display!" + E.toString ()); ; }} Hold (exception e) {Log.e ("log_tag", "Error in http connection !!" + e.toString ()); }}}); } }
My question is how can I pass data from the edit text Android to the php query so that queries can return only the right items
(New BasicNameValuePairs ("ID", Data));
Add
to your PHP script (isset ($ _ POST ['id']) {var id = $ _POST ['id']; // do db operation here} id = your data ID and data = your data.
Comments
Post a Comment