简体   繁体   中英

I just want to insert data into mysql database php using volley android

As I'm a beginner. Can anyone help me how to insert data into MySQL database using volley method? What should I try Volley or Retrofit? Can anyone help me with some example of how to add the data to the MySQL database?

String Name,Email,Mobile,DOB;

final EditText name,email,mobile,dob;
Button insert;

name = (EditText) findViewById(R.id.name);
email = (EditText) findViewById(R.id.email);
mobile = (EditText) findViewById(R.id.mobile);
dob = (EditText) findViewById(R.id.dob);

insert = (Button) findViewById(R.id.insert);

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

            Name = name.getText().toString();
            Email = email.getText().toString();
            Mobile = mobile.getText().toString();
            DOB = dob.getText().toString();

            insertdb();
        }

        private void insertdb() {

            final TextView textView = (TextView) findViewById(R.id.text);

// Instantiate the RequestQueue.

RequestQueue queue = Volley.newRequestQueue(getApplicationContext());

String url ="http://ganeshkumar.epizy.com/insertdb.php? 
name="+Name+"&email="+Email+"&mobile="+Mobile+"&dob="+DOB;

// Request a string response from the provided URL.

StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                    new Response.Listener<String>() {
                        @Override
                        public void onResponse(String response) {

// Display the first 500 characters of the response string.

textView.setText("Response is: "+ response.substring(0,500)); Toast.makeText(getApplicationContext(),"Success",Toast.LENGTH_LONG).show();

                        }
                    }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

textView.setText("That didn't work!"); Toast.makeText(getApplicationContext(),"Failed",Toast.LENGTH_LONG).show();
                }
            });

// Add the request to the RequestQueue.
            queue.add(stringRequest);

        }
});

I Actually don't know how to send the data that I was assigned to the String to the PHP

If you are using Volly please go through this link
You can use Http Post also.. Please refer this link
Please change your php files accordingly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM