Android Php login error , namevalued pairs sending blank data
<p>I wanted to create a login page in android which connects to a my sql database</p>

<p>Android Code --</p>

<pre><code>public class Hetro01Activity extends Activity implements OnClickListener {

    EditText uname;
    EditText password;
    Button ok;
    ArrayList&lt;NameValuePair&gt; nameValuePairs;
    @Override
    public void onCreate(Bundle savedInstanceState) {         
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ok=(Button)findViewById(R.id.submit);

        ok.setOnClickListener(this);


    }

    public void onClick(View vu)

    {
        switch(vu.getId())
        {
        case R.id.submit:

             uname=(EditText)findViewById(R.id.uname);
             password=(EditText)findViewById(R.id.password);

            nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);
            nameValuePairs.add(new BasicNameValuePair("uname",uname.getText().toString().trim()));
            nameValuePairs.add(new BasicNameValuePair("password",password.getText().toString().trim()));


        String result=null;
        InputStream is=null; 
        try
        {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://www.hetroservers.orgfree.com/login1/checklogin.php");
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            HttpResponse response=httpclient.execute(httppost);

            HttpEntity entity=response.getEntity();

            is=entity.getContent();
            Log.e("response",is.toString());    
            try
            {
                BufferedReader br=new BufferedReader(new InputStreamReader(is),8);
                StringBuilder sb=new StringBuilder();
                String line=null;

                while((line=br.readLine())!=null)
                {
                    sb.append(line+"\n");

                }
                is.close();

                result=sb.toString();
                result= result.replaceAll("\\s+",""); 
                Toast.makeText(getApplicationContext(), sb, Toast.LENGTH_LONG).show();  
                //validate(result);
                      }
            catch(Exception e)
            {
                  Log.e("log_tag2", "Error");
            }



        }
        catch(Exception e)
        {
            Log.e("log_tag", "Error:  "+e.toString());
        }


        }   
        }

    public void validate(String res)
    {
        if(res.equals("Session Created"))
        {

            Intent myInt=new Intent(this,Main1.class);
            startActivity(myInt);

        }
        else
        {


        }

    }
    }
</code></pre>

<p>and the php code is  </p>

<pre><code>mysql_connect("$host", "$user", "$pass")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
$myusername=$_REQUEST['uname']; 
$mypassword=$_REQUEST['password']; 

$insert="INSERT INTO hetrologin(username,password) VALUES ('$myusername','$mypassword')";
$init=mysql_query($insert);

$sql="SELECT username FROM hetrologin WHERE username= '$myusername' AND password= '$mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count == 1){
echo "1";
}
else{
echo "Wrong Username or Password";
}


?&gt;  
</code></pre>

<p>I wanted to check where the error was so used an insert statement to check in my db, i notice that no matter what input i give the db only stores blank values for both username and password, when i tried the same via a get request to server from my browser the data is being stored properly. Any idea why?</p>
