title: Unable to Signup and Login using JSON parameter in android
body: <p>Login JSON RESPONSE</p>
  
  <pre><code>{"VerifiedMember":[{"user_id":"23","first_name":"karan","phone":""}],"success":1,"message":"success"}
  </code></pre>
  
  <p>SignUp JSON RESPONSE</p>
  
  <pre><code>{"RegisteredMember":[{"user_id":61,"first_name":"p","phone":"9726068072"}],"success":1,"message":"Registration Successful"}
  </code></pre>
  
  <p>Login Activity Class</p>
  
  <pre><code> public class Login extends AppCompatActivity implements View.OnClickListener{
      private static final String TAG = Login.class.getSimpleName();
      private EditText email, password;
      private Button login;
      private TextView signup;
      private ProgressDialog progressDialog;
      private UserSession session;
      private UserInfo userInfo;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login);
  
          email        = (EditText)findViewById(R.id.email);
          password        = (EditText)findViewById(R.id.password);
          login           = (Button)findViewById(R.id.login);
          signup          = (TextView)findViewById(R.id.open_signup);
          progressDialog  = new ProgressDialog(this);
          session         = new UserSession(this);
          userInfo        = new UserInfo(this);
  
          if(session.isUserLoggedin()){
              startActivity(new Intent(this, MainActivity.class));
              finish();
          }
  
          login.setOnClickListener(this);
          signup.setOnClickListener(this);
      }
  
      private void login(final String email, final String password){
          // Tag used to cancel the request
          String tag_string_req = "req_login";
          progressDialog.setMessage("Logging in...");
          progressDialog.show();
  
          StringRequest strReq = new StringRequest(Request.Method.POST,
                  Utils.LOGIN_URL, new Response.Listener&lt;String&gt;() {
  
              @Override
              public void onResponse(String response) {
                  Log.d(TAG, "Login Response: " + response.toString());
                  progressDialog.hide();
                  try {
                      JSONObject jObj = new JSONObject(response);
                      int intError = jObj.getInt("success");
                      boolean error = (intError &gt; 0) ? true : false;
  
  
                          // Check for error node in json
                          if (!error) {
                              // Now store the user in SQLite
  
                              String uid = jObj.getString("user_id");
                              JSONObject user = jObj.getJSONObject("VerifiedMember");
                              String uName = user.getString("first_name");
                              String email = user.getString("phone");
  
  
                              // Inserting row in users table
                              userInfo.setEmail(email);
                              userInfo.setFirstname(uName);
                              userInfo.setUid(uid);
                              session.setLoggedin(true);
                              Intent i = new Intent(Login.this, Home.class);
                              startActivity(i);
  
  
  
                          } else {
                              // Error in login. Get the error message
                              String errorMsg = jObj.getString("message");
                              toast(errorMsg);
  
  
                          }
                   //   }
                  }catch (JSONException e) {
                      // JSON error
                      e.printStackTrace();
                      toast("Json error: " + e.getMessage());
                  }
  
              }
          }, new Response.ErrorListener() {
  
              @Override
              public void onErrorResponse(VolleyError error) {
                  Log.e(TAG, "Login Error: " + error.getMessage());
                  toast("Unknown Error occurred");
                  progressDialog.hide();
              }
          }) {
  
              @Override
              protected Map&lt;String, String&gt; getParams() {
                  // Posting parameters to login url
                  Map&lt;String, String&gt; params = new HashMap&lt;&gt;();
                  params.put("username", email);
                  params.put("password", password);
  
                  return params;
              }
  
          };
  
          // Adding request to request queue
          AndroidLoginController.getInstance().addToRequestQueue(strReq, tag_string_req);
      }
  
      private void toast(String x){
          Toast.makeText(this, x, Toast.LENGTH_SHORT).show();
      }
  
      @Override
      public void onClick(View v) {
          switch (v.getId()){
              case R.id.login:
                  String uName1 = email.getText().toString().trim();
                  String pass  = password.getText().toString().trim();
  
                  login(uName1, pass);
                  break;
              case R.id.open_signup:
                  startActivity(new Intent(this, SignUp.class));
                  break;
          }
      }
  }
  </code></pre>
  
  <p>Signup Activity Class</p>
  
  <pre><code>public class SignUp extends AppCompatActivity {
      private String TAG = SignUp.class.getSimpleName();
      private EditText username, email, password, gender, bdate, fname, lname;
      private Button signup;
      private ProgressDialog progressDialog;
      private UserSession session;
      private UserInfo userInfo;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_sign_up);
          fname = (EditText) findViewById(R.id.first_name);
          lname = (EditText) findViewById(R.id.last_name);
          gender = (EditText) findViewById(R.id.gender);
          bdate = (EditText) findViewById(R.id.bdate);
  
        //  username = (EditText) findViewById(R.id.username);
          email = (EditText) findViewById(R.id.email_or_phone);
          password = (EditText) findViewById(R.id.password);
          signup = (Button) findViewById(R.id.signup);
          progressDialog = new ProgressDialog(this);
          session = new UserSession(this);
          userInfo = new UserInfo(this);
  
          signup.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  String fName = fname.getText().toString().trim();
  
                  String lName = lname.getText().toString().trim();
  
                  String gen = gender.getText().toString().trim();
  
                  String dob = bdate.getText().toString().trim();
  
  
                  String mail = email.getText().toString().trim();
                  String pass = password.getText().toString().trim();
  
  
  
                  signup(fName,lName,gen,dob, mail, pass);
              }
          });
      }
  
      private void signup(final String firstName,final String lastName, final String gend,  final String dobd,final String email, final String password) {
          // Tag used to cancel the request
          String tag_string_req = "req_signup";
          progressDialog.setMessage("Signing up...");
          progressDialog.show();
  
          StringRequest strReq = new StringRequest(Request.Method.POST,
                  Utils.REGISTER_URL, new Response.Listener&lt;String&gt;() {
  
              @Override
              public void onResponse(String response) {
                  Log.d(TAG, "Register Response: " + response.toString());
  
                  try {
                      JSONObject jObj = new JSONObject(response);
                      int intError = jObj.getInt("success");
                      boolean error = (intError &gt; 0) ? true : false;
  
                      // Check for error node in json
                      if (!error) {
                          JSONObject user = jObj.getJSONObject("RegisteredMember");
                          String firstName = user.getString("first_name");
                          String LastName = user.getString("last_name");
                          String email = user.getString("register_nm");
                          String dobd = user.getString("bdate");
                          String gender = user.getString("gender");
                          String password = user.getString("password");
  
                          // Inserting row in users table
                          userInfo.setEmail(email);
                          userInfo.setFirstname(firstName);
                          userInfo.setLastname(LastName);
                          userInfo.setdob(dobd);
                          userInfo.setGender(gender);
                          userInfo.setPassword(password);
  
                          session.setLoggedin(true);
  
                          startActivity(new Intent(SignUp.this, MainActivity.class));
                      } else {
                          // Error in login. Get the error message
                          String errorMsg = jObj.getString("success");
                          toast(errorMsg);
                      }
                  } catch (JSONException e) {
                      // JSON error
                      e.printStackTrace();
                      toast("Json error: " + e.getMessage());
                  }
  
              }
          }, new Response.ErrorListener() {
  
              @Override
              public void onErrorResponse(VolleyError error) {
                  Log.e(TAG, "Login Error: " + error.getMessage());
                  toast("Unknown Error occurred");
                  progressDialog.hide();
              }
          }) {
  
              @Override
              protected Map&lt;String, String&gt; getParams() {
                  // Posting parameters to login url
                  Map&lt;String, String&gt; params = new HashMap&lt;&gt;();
                  params.put("first_name", firstName);
                  params.put("last_name", lastName);
                  params.put("gender",gend);
                  params.put("bdate",dobd);
                  params.put("phone", email);
                  params.put("password", password);
  
                  return params;
              }
  
          };
  
          // Adding request to request queue
          AndroidLoginController.getInstance().addToRequestQueue(strReq, tag_string_req);
      }
  
      private void toast(String x) {
          Toast.makeText(this, x, Toast.LENGTH_SHORT).show();
      }
  }
  </code></pre>
  
  <p>UserInfo Class</p>
  
  <pre><code>public class UserInfo {
      private static final String TAG = UserSession.class.getSimpleName();
      private static final String PREF_NAME = "userinfo";
      private static final String KEY_FIRSTNAME = "first_name";
      private static final String KEY_LASTNAME = "last_name";
      private static final String KEY_GENDER = "gender";
      private static final String KEY_DOB = "bdate";
      private static final String KEY_PASSWORD = "password";
      private static final String KEY_EMAIL_PHONE = "phone";
      SharedPreferences prefs;
      SharedPreferences.Editor editor;
      Context ctx;
  
      public UserInfo(Context ctx) {
          this.ctx = ctx;
          prefs = ctx.getSharedPreferences(PREF_NAME, ctx.MODE_PRIVATE);
          editor = prefs.edit();
      }
  
      public void setFirstname(String firstname){
          editor.putString(KEY_FIRSTNAME, firstname);
          editor.apply();
      }
       public  void setLastname (String lastname){
          editor.putString(KEY_LASTNAME, lastname);
          editor.apply();
      } public  void setGender (String gender){
          editor.putString(KEY_GENDER, gender);
          editor.apply();
      } public  void setdob (String dob){
          editor.putString(KEY_DOB, dob);
          editor.apply();
      } public  void setPassword (String password) {
          editor.putString(KEY_PASSWORD, password);
          editor.apply();
      }
  
      public void setEmail(String email){
          editor.putString(KEY_EMAIL_PHONE, email);
          editor.apply();
      }
  
      public void clearUserInfo(){
          editor.clear();
          editor.commit();
      }
  
      public String getKeyFirstname(){return prefs.getString(KEY_FIRSTNAME, "");}
      public String getKeyEmail(){return prefs.getString(KEY_EMAIL_PHONE, "");}
    public String getKeyLastname(){return prefs.getString(KEY_LASTNAME,"");}
    public String getKeyGender(){return prefs.getString(KEY_GENDER,"");}
    public String getKeyDob(){return prefs.getString(KEY_DOB,"");}
    public String getKeyPassword(){return prefs.getString(KEY_PASSWORD,"");}
  
  
  }
  </code></pre>
  
  <p>MainActivity Class</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      private Button logout;
      private TextView tvUsername, tvEmail;
      private UserInfo userInfo;
      private UserSession userSession;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          userInfo        = new UserInfo(this);
          userSession     = new UserSession(this);
          logout          = (Button)findViewById(R.id.logout);
          tvUsername      = (TextView)findViewById(R.id.key_username);
          tvEmail         = (TextView)findViewById(R.id.key_email);
  
          if(!userSession.isUserLoggedin()){
              startActivity(new Intent(this, Login.class));
              finish();
          }
  
          String username = userInfo.getKeyFirstname();
          String email    = userInfo.getKeyEmail();
  
          tvUsername.setText(username);
          tvEmail.setText(email);
  
          logout.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  userSession.setLoggedin(false);
                  userInfo.clearUserInfo();
                  startActivity(new Intent(MainActivity.this, Login.class));
                  finish();
              }
          });
  
  
      }
  
  }
  </code></pre>
  
  <p>User Session Class</p>
  
  <pre><code>public class UserSession {
      private static final String TAG = UserSession.class.getSimpleName();
      private static final String PREF_NAME = "login";
      private static final String KEY_IS_LOGGED_IN = "isloggedin";
      SharedPreferences prefs;
      SharedPreferences.Editor editor;
      Context ctx;
  
      public UserSession(Context ctx) {
          this.ctx = ctx;
          prefs = ctx.getSharedPreferences(PREF_NAME, ctx.MODE_PRIVATE);
          editor = prefs.edit();
      }
  
      public void setLoggedin(boolean isLoggedin){
          editor.putBoolean(KEY_IS_LOGGED_IN, isLoggedin);
          editor.apply();
      }
  
      public boolean isUserLoggedin(){return prefs.getBoolean(KEY_IS_LOGGED_IN, false);}
  }
  </code></pre>
  
  <p>SIGNUP PHP CODE </p>
  
  <pre><code>&lt;?php
  require '../db_connect.php';
  require "../classes/class.phpmailer.php";
  
  if(isset($_POST['first_name']) &amp;&amp; !empty($_POST['first_name']) &amp;&amp; isset($_POST['last_name']) &amp;&amp; !empty($_POST['last_name']) &amp;&amp; isset($_POST['password']) &amp;&amp; !empty($_POST['password']) &amp;&amp; isset($_POST['bdate']) &amp;&amp; !empty($_POST['bdate']) &amp;&amp; isset($_POST['gender']) &amp;&amp; !empty($_POST['gender'])){
  
  $first_name=$_POST['first_name'];
  $last_name=$_POST['last_name'];
  //$email=$_POST['email'];
  //$phone=$_POST['phone'];
  $password=$_POST['password'];
  $birthdate=$_POST['bdate'];
  $gender=$_POST['gender'];
  
  if(is_numeric($register_name))
  {
      $email="";
      $phone=$register_name;
      if(!preg_match("/^([0-9][0-9]{9})$/",$phone)) { 
          $response["success"] = 0;
          $response["message"] = "invalid phone validation";
  
          // echoing JSON response
          echo json_encode($response);
          exit;
      }
      $reg_type=1;
      $email_hash="";
  }
  else{
      $email=$register_name;
      if(!preg_match("/^([_a-z0-9]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,5}))|(\d+$)$/",$email)) { 
         $response["success"] = 0;
          $response["message"] = "invalid email validation";
  
          // echoing JSON response
          echo json_encode($response);
          exit;
      }
      $phone="";
      $reg_type=2;
      $email_hash = md5(rand(0,1000));
  }
  if(!preg_match("/^[a-zA-Z']+$/",$first_name)) { 
      $response["success"] = 0;
      $response["message"] = "invalid firstname validation";
  
      // echoing JSON response
      echo json_encode($response);
      exit;
  }
  if(!preg_match("/^[a-zA-Z']+$/",$last_name)) { 
      $response["success"] = 0;
      $response["message"] = "invalid lastname validation";
  
      // echoing JSON response
      echo json_encode($response);
      exit;
  }
  if(strlen($password) &lt; 6){
      $response["success"] = 0;
      $response["message"] = "invalid password validation";
  
      // echoing JSON response
      echo json_encode($response);
      exit;
  }
  if(!($gender=='male' || $gender=='female')){
      $response["success"] = 0;
      $response["message"] = "invalid gender validation";
  
      // echoing JSON response
      echo json_encode($response);
      exit;   
  }
  if(strtotime($birthdate) &gt; strtotime(date('d-m-Y'))){
      $response["success"] = 0;
      $response["message"] = "invalid bdate validation";
  
      // echoing JSON response
      echo json_encode($response);
      exit;
  }
  function sendOtp($otp, $phone){
          //This is the sms text that will be sent via sms 
          $sms_content = "Your verification code is $otp";
  
          //Encoding the text in url format
          $sms_text = urlencode($sms_content);
  
          $arrContextOptions=array(
          "ssl"=&gt;array(
                  "verify_peer"=&gt;false,
                  "verify_peer_name"=&gt;false,
                  ),
                  );
  
          $api_url = 'https://www.txtguru.in/imobile/api.php?username=candidispin&amp;password=candid@123&amp;source=CANDID&amp;dmobile=91'.$phone.'&amp;message='.$sms_text;
  
          //Envoking the API url and getting the response 
          $response = file_get_contents($api_url);
  
          //Returning the response 
          //return $response;
          //header("location:confirmation.php");
      }
  
      function generateSalt($max = 64) {
          $characterList = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&amp;*?";
          $i = 0;
          $salt = "";
          while ($i &lt; $max) {
              $salt .= $characterList{mt_rand(0, (strlen($characterList) - 1))};
              $i++;
          }
          return $salt;
      }
  
      $user_salt = generateSalt(); // Generates a salt from the function above
      $combo = $user_salt . $password; // Appending user password to the salt 
      $hashed_pwd = hash('sha512',$combo); // Using SHA512 to hash the salt+password combo string
  
      date_default_timezone_set('Asia/Kolkata');
      $date = date('Y-m-d H:i:s');
      //echo $date;
      $otp = rand(100000, 999999);
      $ip_address = $_SERVER['REMOTE_ADDR'];  
  
      $sql="insert into user_registration(email,phone,hashed_password,salt,first_name,last_name,birthdate,gender,created_at,register_type,email_hash,is_active,ip_address) values('".$email."','".$phone."','".$hashed_pwd."','".$user_salt."','".$first_name."','".$last_name."','".$birthdate."','".$gender."','".$date."','".$reg_type."','".$email_hash."',1,'".$ip_address."')";
      //echo $sql;
  
      if(mysqli_query($con,$sql)){
      $response["RegisteredMember"] = array();    
      $user_id=mysqli_insert_id($con);
      $RegisteredMember['user_id'] = $user_id;
  
      $sql = "SELECT * FROM user_registration WHERE id =".$user_id;
      $result = mysqli_fetch_array(mysqli_query($con,$sql));
      $RegisteredMember['first_name'] = $result['first_name'];
      $RegisteredMember['phone'] = $result['phone'];
      array_push($response["RegisteredMember"], $RegisteredMember);
  
      if($reg_type==1){
      $expiration_time=date('Y-m-d H:i:s', strtotime('+1 hours'));
      //echo $expiration_time;
  
      $sql1="INSERT INTO user_otps (user_id, otp, expiration_time) values ('$user_id','$otp','$expiration_time')";
  
      if(mysqli_query($con,$sql1)){
      echo sendOtp($otp,$phone);
  
      }
      }
      else{
          $result1 = mysqli_query($con,"select * from user_authentication");
  
                  if (mysqli_num_rows($result1) &gt; 0) {
                      // output data of each row
  
                          $row1 = mysqli_fetch_array($result1);
                          $company = $row1["Company"];
                          $webemail = $row1["WebEmail"];
                          $username = $row1["Username"];
                          $password = $row1["Password"];
                          $host = $row1["Host"];
                          $port = $row1["Port"];
  
                          $mail   = new PHPMailer; // call the class 
                          $mail-&gt;IsSMTP();  
                          $mail-&gt;Host = $host; //Hostname of the mail server
                          $mail-&gt;Port = $port; //Port of the SMTP like to be 25, 80, 465 or 587
                          $mail-&gt;SMTPAuth = true; //Whether to use SMTP authentication
                          $mail-&gt;SMTPSecure = 'tls';
                          $mail-&gt;Username = $username; //Username for SMTP authentication any valid email created in your domain
                          $mail-&gt;Password = $password; //Password for SMTP authentication
                          //$mail-&gt;AddReplyTo($email, $name); //reply-to address
                          $mail-&gt;SetFrom($webemail, $company); //From address of the mail
                          // put your while loop here like below,
                          $mail-&gt;Subject = "Verification Email"; //Subject od your mail
                          $mail-&gt;AddAddress($webemail, $company); //To address who will receive this email
                          $mail-&gt;AddAddress($email, ""); //To address who will receive this email
                          $url='http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
                          $s_url=$url.'/verify.php?email='.$register_name.'&amp;hash='.$email_hash;
                          $sub =  "Thanks for signing up!&lt;br&gt;Your account has been created&lt;br&gt;Please click this link to verify your account:&lt;br&gt;&lt;a href=".$s_url."&gt;Verification Link&lt;/a&gt;";
                          $mail-&gt;MsgHTML($sub); //Put your body of the message you can place html code here
                          //$mail-&gt;AddAttachment("images/asif18-logo.png"); //Attach a file here if any or comment this line, 
                          $send = $mail-&gt;Send(); //Send the mails
                          if($send)
                          {
                              $response["success"] = 1;
                              $response["message"] = "Mail sent";
  
                              // echoing JSON response
                              echo json_encode($response);
                          }
                          else
                          {
                              $response["success"] = 0;
                              $response["message"] = "Mail not sent";
  
                              // echoing JSON response
                              echo json_encode($response);
                          }
  
                  }
                  else
                  {
                              $response["success"] = 0;
                              $response["message"] = "Mail not sent";
  
                              // echoing JSON response
                              echo json_encode($response);
                  }
  
  
      }
      $response["success"] = 1;
      $response["message"] = "Registration Successful";
  
      // echoing JSON response
      echo json_encode($response);
      }
      mysqli_close($con);
  }
  else{
      $response["success"] = 0;
      $response["message"] = "Parameters are not set";
  
      echo json_encode($response);
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>LOGIN PHP CODE</p>
  
  <pre><code>&lt;?php
  require '../db_connect.php';
  if (isset($_POST['username']) &amp;&amp; !empty($_POST['username']) &amp;&amp; isset($_POST['password']) &amp;&amp; !empty($_POST['password']))
  {
      $myusername = $_POST['username'];
      $mypassword = $_POST['password']; 
      $sql = "SELECT * FROM user_registration WHERE (username = '$myusername' or email = '$myusername' or phone = '$myusername')";
      $result = mysqli_query($con,$sql);
      if(mysqli_num_rows($result)&gt;0){
  
      $response["VerifiedMember"] = array();
      $row = mysqli_fetch_array($result);
      $VerifiedMember = array();
          $id=$row['id'];
          $phone=$row['phone'];
          $reg_type=$row['register_type'];
          $stored_salt = $row['salt'];
          $stored_hash = $row['hashed_password'];
          $check_pass = $stored_salt . $mypassword;
          $check_hash = hash('sha512',$check_pass);
  
          if($check_hash == $stored_hash){
  
              $VerifiedMember['user_id'] = $id;
              $VerifiedMember['first_name']=$row['first_name'];
              $VerifiedMember['phone']=$row['phone'];
              array_push($response["VerifiedMember"], $VerifiedMember);
  
           if(!empty($phone)&amp;&amp; $reg_type==1){
  
               $sql="select * from user_otps where user_id='".$id."'";
               $result = mysqli_query($con,$sql);
               if(mysqli_num_rows($result)&gt;0){
                  $row = mysqli_fetch_array($result);
                  if($row['verified']==0)
                  {
                      //no product found
                        $response["success"] = 0;
                        $response["message"] = "failure";
  
                      // echo no users JSON
                      echo json_encode($response);
  
                  }
                  else
                  {   
                      //no product found
                        $response["success"] = 1;
                        $response["message"] = "success";
  
                      // echo no users JSON
                      echo json_encode($response);
                  }
               }
           }
           else{
                      //no product found
                        $response["success"] = 1;
                        $response["message"] = "success";
  
                      // echo no users JSON
                      echo json_encode($response);
           }
           //echo json_encode($response);
          }
  
          else{
                      //no product found
                        $response["success"] = 0;
                        $response["message"] = "invalid";
  
                      // echo no users JSON
                      echo json_encode($response);
          }
      }
      else{
                      //no product found
                        $response["success"] = 0;
                        $response["message"] = "invalid";
  
                      // echo no users JSON
                      echo json_encode($response);
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Here i am getting error in log 
  the error is 
  Register Response: {"success":0,"message":"Parameters are not set"}
  org.json.JSONException: No value for RegisteredMember</p>
  
  <p>Can anyone help me to Make  Login and Signup using this code </p>