title: how to post data from android to PHP(simple)?
body: <p>I am trying to send data by a very simple way to PHP from Android, but always I am getting error.
  Please tell me how to make it to work, what am I doing wrong?</p>
  
  <h2>PHP code</h2>
  
  <pre><code>&lt;?php  
  require 'connect.inc.php';
  mysql_query("INSERT INTO 'names' VALUES ('2','".$_POST['name']."')");
  ?&gt;
  </code></pre>
  
  <h2>Android code</h2>
  
  <pre><code>HttpClient httpclient = new DefaultHttpClient();
  HttpPost httppost = new HttpPost(url);
  try {
      List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair(1);
      nameValuePairs.add(new BasicNameValuePair("name", "Alex"));
      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
      HttpResponse response = httpclient.execute(httppost);
  } catch(Eexceptions....){}
  </code></pre>
  
  <h2>Log_cat</h2>
  
  <pre><code>01-12 09:02:00.980: E/AndroidRuntime(942): FATAL EXCEPTION: main
  01-12 09:02:00.980: E/AndroidRuntime(942): Process: com.example.httpjsonphp3, PID: 942
  01-12 09:02:00.980: E/AndroidRuntime(942): java.lang.IllegalStateException: Could not execute method of the activity
  01-12 09:02:00.980: E/AndroidRuntime(942):  at android.view.View$1.onClick(View.java:3814)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at android.view.View.performClick(View.java:4424)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at android.view.View$PerformClick.run(View.java:18383)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at android.os.Handler.handleCallback(Handler.java:733)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at android.os.Handler.dispatchMessage(Handler.java:95)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at android.os.Looper.loop(Looper.java:137)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at android.app.ActivityThread.main(ActivityThread.java:4998)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at java.lang.reflect.Method.invokeNative(Native Method)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at java.lang.reflect.Method.invoke(Method.java:515)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at dalvik.system.NativeStart.main(Native Method)
  01-12 09:02:00.980: E/AndroidRuntime(942): Caused by: java.lang.reflect.InvocationTargetException
  01-12 09:02:00.980: E/AndroidRuntime(942):  at java.lang.reflect.Method.invokeNative(Native Method)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at java.lang.reflect.Method.invoke(Method.java:515)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at android.view.View$1.onClick(View.java:3809)
  01-12 09:02:00.980: E/AndroidRuntime(942):  ... 11 more
  01-12 09:02:00.980: E/AndroidRuntime(942): Caused by: android.os.NetworkOnMainThreadException
  01-12 09:02:00.980: E/AndroidRuntime(942):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1145)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at java.net.InetAddress.getAllByName(InetAddress.java:214)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
  01-12 09:02:00.980: E/AndroidRuntime(942):  at com.example.httpjsonphp3.MainActivity.onSend(MainActivity.java:39)
  01-12 09:02:00.980: E/AndroidRuntime(942):  ... 14 more
  01-12 09:02:07.050: I/Process(942): Sending signal. PID: 942 SIG: 9
  </code></pre>