Click here to Skip to main content
14,879,334 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I was given assignment on android mysql http url connection. The assignment is as follows

Registering Users
POST END POINT
http://edeeki.com/webservice/Registeredservice.php
Explanation: We would use this end point to register users by sending the following post keys
Usage: send these post keys
$_POST["register"] = 1 and $_POST['email']

I already have a code that i used for a project sometimes ago user registration, see code below

public class MainActivity extends AppCompatActivity {

    Button register , login ;
    EditText phone;
    String RegisterURL = "http://192.168.137.164/andoidphonelogreg/insert-registration-data.php" ;
    Boolean CheckEditText ;
    String Response;
    HttpResponse response ;
    String EmailHolder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        register = (Button)findViewById(R.id.button);
        login = (Button)findViewById(R.id.button2);

        phone = (EditText)findViewById(R.id.phone);
        phone.addTextChangedListener(new PhoneNumberFormattingTextWatcher());

        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                GetCheckEditTextIsEmptyOrNot();

                if(CheckEditText){

                    SendDataToServer(EmailHolder);

                }
                else {

                    Toast.makeText(MainActivity.this, "Please fill all form field.", Toast.LENGTH_LONG).show();

                }


            }
        });

        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(MainActivity.this, LoginActivity.class);
                startActivity(intent);

            }
        });
    }

    public void GetCheckEditTextIsEmptyOrNot(){

        EmailHolder = phone.getText().toString();

        if(TextUtils.isEmpty(EmailHolder))
        {

            CheckEditText = false;

        }
        else {

            CheckEditText = true ;
        }

    }

    public void SendDataToServer( final String phone){
        class SendPostReqAsyncTask extends AsyncTask<String, Void, String> {
            @Override
            protected String doInBackground(String... params) {

                String QuickEmail = phone ;

                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

                nameValuePairs.add(new BasicNameValuePair("phone", QuickEmail));

                try {
                    HttpClient httpClient = new DefaultHttpClient();

                    HttpPost httpPost = new HttpPost(RegisterURL);

                    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                    HttpResponse response = httpClient.execute(httpPost);

                    HttpEntity entity = response.getEntity();


                } catch (ClientProtocolException e) {

                } catch (IOException e) {

                }
                return "Registration Successful, Login Now!!!";
            }

            @Override
            protected void onPostExecute(String result) {
                super.onPostExecute(result);

                Toast.makeText(MainActivity.this, "Registration Successfully, Login Now!!!", Toast.LENGTH_LONG).show();

            }
        }
        SendPostReqAsyncTask sendPostReqAsyncTask = new SendPostReqAsyncTask();
        sendPostReqAsyncTask.execute(phone);
    }
}

My question is how can i use the information above i.e send these post keys $_POST["register"] = 1 and $_POST['email'] to register users in my app using the code i already have.
Thanks in advance

What I have tried:

have searched google and still asking friends
Posted
Comments
wseng 19-Jun-18 21:48pm
   
Well explanation https://kosalgeek.com/android-php-mysql-login-registration-cache-sharedpreferences/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900