Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dependencies{
- compile 'com.squareup.okhttp:okhttp:2.0.0'
- }
- btnRegistration.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- try {
- String UserName = etUserName.getText().toString();
- String Password = etPassword.getText().toString();
- String DOB = etDob.getText().toString();
- String Phone = etPhone.getText().toString();
- String inserturl = "http://10.0.2.2/Project/Registration.php?insert&username="+UserName+"&password="+Password
- +"&dob="+DOB+"phone="+Phone;
- JSONObject jsonObject = new JSONParser().SelectData(inserturl);
- if (jsonObject != null)
- {
- Toast.makeText(MainActivity.this, jsonObject.toString(), Toast.LENGTH_SHORT).show();
- }
- }catch (Exception ex){
- Log.i("Error",ex.toString());
- }
- }
- });
- public class JSONParser {
- public JSONObject SelectData(String url){
- try {
- OkHttpClient client = new OkHttpClient();
- Request request = new Request.Builder().url(url).build();
- Response response = client.newCall(request).execute();
- String data = response.body().string();
- JSONObject jsonObject = new JSONObject(data);
- return jsonObject;
- }catch(Exception ex){
- return null;
- }
- }
- }
- <?php
- include "Mysql.php";
- $username = $_GET['user'];
- $password = $_GET['pass'];
- $dob =date("Y-m-d" ,strtotime($_GET['dob']));
- $phone = $_GET['phone'];
- $sql_query = "insert into registration(username,password,dob,phoneno) values('$username','$password','$dob','$phone')";
- if(mysqli_query($conn,$sql_query))
- {
- echo"<h3>Data Insertion Success...</h3>";
- }else{
- echo "Data Insertion error..".mysqli_error($conn);
- }
- ?>
Add Comment
Please, Sign In to add comment