title: Send data from Android to Webservice to be inserted in my database
body: <p>I'm trying to send a few variables(or data) for registration to a webservice from android throught "httppost" method. Here's the code.</p>
  
  <pre><code>HttpClient httpclient = new DefaultHttpClient();
  HttpPost httppost = new HttpPost("http://mywebsitename.com/webservice/register.php");
  try {
   List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(4);
  
  nameValuePairs.add(new BasicNameValuePair("fname", et3.getText().toString()));
   nameValuePairs.add(new BasicNameValuePair("lname", et4.getText().toString()));
   nameValuePairs.add(new BasicNameValuePair("userid", et5.getText().toString()));
   nameValuePairs.add(new BasicNameValuePair("pass", et6.getText().toString()));
   httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
   httpclient.execute(httppost);
  
   } catch (ClientProtocolException e) {
                           // TODO Auto-generated catch block
   } catch (IOException e) {
                           // TODO Auto-generated catch block
  }
  </code></pre>
  
  <p>Following is the Register.php file code.</p>
  
  <pre><code>&lt;?php
  $host = "localhost"; 
  $user = "myusername"; 
  $pass = "mypass";
  $connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."&lt;BR&gt;");
  
  $fname = $_POST['fname'];
  $lname = $_POST['lname'];
  $userid = $_POST['userid'];
  $pass = $_POST['pass'];
  
  $db_select=mysql_select_db("the_db");
  if(!$db_select){
      die(mysql_error());
      echo "error";
  }
  
  $query= "INSERT INTO USERS(fname, lname, userid, pass)
  VALUES ('{$fname}', '{$lname}', '{$userid}', '{$pass}'); " ;
  
  if($medo=mysql_query($query)){
      header("localhost/filename");
      exit;
  }else{
      echo"&lt;p&gt; Error&lt;/p&gt;";
      die(mysql_error());
  }
  </code></pre>
  
  <p>When I try to run it, gives me an error. It says on my device that "YourApp has stopped working". Possibly a nullpointer exception or something like that. I don't know if this is the correct way to send simple variables like names and passwords etc. to the register.php. Can you tell me what the problem is here?</p>