Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help in posting data to MySQL using PHP from Android
    text
    copied!<p>I am developing a sample android app which has two EditTexts and a 'Save' button. It gets data from EditTexts and posts it to MySQL server using PHP. The code is blow.</p> <p>My onClick method to save data</p> <pre><code> public void saveMy(View v) { name=e1.getText().toString(); no=e2.getText().toString(); try { httpclient = new DefaultHttpClient(); httppost = new HttpPost("http://10.0.2.2/GujaratiApp/myPHP.php"); ArrayList&lt;NameValuePair&gt; postParameters = new ArrayList&lt;NameValuePair&gt;(); postParameters.add(new BasicNameValuePair("Name",name)); postParameters.add(new BasicNameValuePair("No",no)); httppost.setEntity(new UrlEncodedFormEntity(postParameters)); HttpResponse response = httpclient.execute(httppost); Log.i("postData", response.getStatusLine().toString()); } catch(Exception ex) { Log.e("log_tag", "Error: "+ex.toString()); } } </code></pre> <p>The PHP code is:</p> <pre><code>&lt;?php mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("newDB"); $name = $_POST['Name']; $no = $_POST['No'] ; $query_add="INSERT INTO myData (`name` ,`no` ) VALUES ('.$name','.$no')"; $query_exec=mysql_query($query_add) or die(mysql_error()); mysql_close(); </code></pre> <p>?></p> <p>When I click the Save button there is a message in LogCat that HTTP/1.1 200 OK. And when I fire query in MySQL monitor it adds one row to the table but the added row doesn't show anything. See image below:<img src="https://i.stack.imgur.com/7ksdS.png" alt="enter image description here"></p> <p>I don't know what is going wrong.. Please help me out.</p> <p>Thanks in advance.</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