same error message displaying on every condition in onpostexecute method in android studio

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Jul 13, 2016 1:01:25 PM via Website

If new user signups it should show "success" message and if user is already exists then it should show "fail" message but for all conditions somehow its showing "Error parsing JSON Please data Fill all the records." this message.Also if user is new and he register for new account the db gets updated with his particular details but shows him error message, how can we solve this issue ? any suggestion or help? Following code checks the mysql db records (for exist and new users).

    public class SignupActivity extends AsyncTask<String, Void, String> {

        private Context context;

        public SignupActivity(Context context) {
            this.context = context;

        protected void onPreExecute() {


        protected String doInBackground(String... arg0) {
            String fullName = arg0[0];
          //  String userName = arg0[1];
            String passWord = arg0[1];
            String phoneNumber = arg0[2];
            String emailAddress = arg0[3];

            String link;
            String data;
            BufferedReader bufferedReader;
            String result;

            try {
                data = "?fullname=" + URLEncoder.encode(fullName, "UTF-8");
            //    data += "&username=" + URLEncoder.encode(userName, "UTF-8");
                data += "&password=" + URLEncoder.encode(passWord, "UTF-8");
                data += "&phonenumber=" + URLEncoder.encode(phoneNumber, "UTF-8");
                data += "&emailaddress=" + URLEncoder.encode(emailAddress, "UTF-8");

              link =tryr.php;//https

                URL url = new URL(link);
                HttpURLConnection con = (HttpURLConnection) url.openConnection();

                bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
                result = bufferedReader.readLine();
                return result;
            } catch (Exception e) {
                return new String("Exception: " + e.getMessage());

        protected void onPostExecute(String result) {
            String jsonStr = result;
            if (jsonStr != null) {
                try {
                    JSONObject jsonObj = new JSONObject(jsonStr);
                    String query_result = jsonObj.getString("query_result");
                    if (query_result.equals("SUCCESS")) {
                        Toast.makeText(context, "Data inserted successfully. Signup successfull.", Toast.LENGTH_LONG).show();

                    } else if (query_result.equals("FAILURE")) {
                        Toast.makeText(context, "Data could not be inserted. Signup failed.", Toast.LENGTH_SHORT).show();

                    else {
                        Toast.makeText(context, "Couldn't connect to remote database.", Toast.LENGTH_SHORT).show();
                } catch (JSONException e) {
                    Toast.makeText(context, "Error parsing JSON Please data Fill all the records.", Toast.LENGTH_SHORT).show();

            } else {
                Toast.makeText(context, "Couldn't get any JSON data.", Toast.LENGTH_SHORT).show();

                                       // This code checks if the user already exists or not and send to above code for further queries like displaying messages

                                        if (mysqli_connect_errno($con))
                                           echo '{"query_result":"ERROR"}';

                                        $fullName = $_GET['fullname'];
                                        //$userName = $_GET['username'];
                                        $passWord = $_GET['password'];
                                        $phoneNumber = $_GET['phonenumber'];
                                        $emailAddress = $_GET['emailaddress'];

                                                    $sql = "SELECT * FROM users10 WHERE phone='$phoneNumber' OR email='$emailAddress'";

                                                    $check = mysqli_fetch_array(mysqli_query($con,$sql));

                                                          echo '{"query_result":"FAIL"}';
                                                         $sql = "INSERT INTO users10 (fullname,password,phone,email) VALUES('$fullName','$passWord','$phoneNumber','$emailAddress')";


                                                                         if($result == true) {
                                                                         echo '{"query_result":"SUCCESS"}';
                                                                          echo '{"query_result":"FAILURE"}';