title: Android Login Using PHP, MySQL and Volley
body: <p>I am trying to create a login activity in android using volley. I've set up my database on localhost phpmyadmin. I've created register activity successfully but whenever I try to login from the email and password that I just registered in the database suddenly my application crashes.</p>
  
  <p>here is my login.php</p>
  
  <pre><code> &lt;?php
   if($_SERVER['REQUEST_METHOD']=='POST'){
   $email = $_POST['email'];
   $password = $_POST['password'];
  
   require_once('connection.php');
  
   $sql = "select * from person where email='$email' and password='$password'";
  
   $check = mysqli_fetch_array(mysqli_query($connect,$sql));
  
   if(isset($check)){
   echo "success";
   }else{
   echo "Invalid Username or Password";
   }
  
   }else{
   echo "error try again";
   }
   ?&gt;
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.mememe.project"&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity android:name=".LoginActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity android:name=".RegisterActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.RegisterActivity" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity android:name=".ProfileActivity"&gt;&lt;/activity&gt;
      &lt;/application&gt;
     &lt;/manifest&gt;
  </code></pre>
  
  <p>LoginActivity.java</p>
  
  <pre><code>package com.example.mememe.project;
  
  import android.content.Intent;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import com.android.volley.AuthFailureError;
  import com.android.volley.Request;
  import com.android.volley.RequestQueue;
  import com.android.volley.Response;
  import com.android.volley.VolleyError;
  import com.android.volley.toolbox.StringRequest;
  import com.android.volley.toolbox.Volley;
  
  import java.util.HashMap;
  import java.util.Map;
  
  public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
  
      EditText etEmail, etPassword;
      Button login;
  
      StringRequest request;
      RequestQueue requestQueue;
  
      public static final String EMAIL = "email";
      public static final String PASSWORD = "password";
      private static final String LOGIN_URL = "http://192.XXX.XX.XX/loginApp/login.php";
  
          @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login);
  
          requestQueue = Volley.newRequestQueue(this);
  
          email = (EditText) findViewById(R.id.etEmail);
          password = (EditText) findViewById(R.id.etPassword);
  
          login = (Button) findViewById(R.id.logIn);
  
          login.setOnClickListener(this);
      }
  
      @Override
      public void onClick(View v) {
          userLogin(email.getText().toString(), password.getText().toString());
      }
  
      private void userLogin(final String email, final String password){
  
          StringRequest stringRequest = new StringRequest(Request.Method.POST, LOGIN_URL, new Response.Listener&lt;String&gt;() {
              @Override
              public void onResponse(String response) {
                  if(response.trim().equals("success")){
                      Intent intent = new Intent();
                      intent.putExtra(EMAIL, email);
                      intent.putExtra(PASSWORD, password);
                      startActivity(intent);
                  }else{
                      Toast.makeText(LoginActivity.this, response, Toast.LENGTH_LONG).show();
                  }
              }
          }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                  Toast.makeText(LoginActivity.this, error.toString(), Toast.LENGTH_LONG).show();
              }
          }){
              @Override
              protected Map&lt;String, String&gt; getParams() throws AuthFailureError {
                  Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                  map.put("email", email);
                  map.put("password", password);
  
                  return map;
              }
          };
  
          requestQueue.add(request);
      }
  }
  </code></pre>
  
  <p>ProfileActivity.java</p>
  
  <pre><code>package com.example.mememe.project;
  
  import android.content.Intent;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.widget.TextView;
  
  public class ProfileActivity extends AppCompatActivity {
  
      private TextView textView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_profile);
  
  
          textView = (TextView) findViewById(R.id.textViewUserName);
  
          Intent intent = getIntent();
  
          textView.setText("welcome" + intent.getStringExtra(LoginActivity.EMAIL));
  
      }
  }
  </code></pre>