1. Are you ready for the Galaxy S20? Here is everything we know so far!

doubt

Discussion in 'Android Development' started by ashishabc, Feb 7, 2016.

  1. ashishabc

    ashishabc Lurker
    Thread Starter

    package com.example.database;

    import android.content.Intent;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.support.design.widget.FloatingActionButton;
    import android.support.design.widget.Snackbar;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.Toolbar;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.Toast;

    import java.io.BufferedWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io_OutputStream;
    import java.io_OutputStreamWriter;
    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLEncoder;

    public class Addinfo extends AppCompatActivity {


    EditText Name,Email,Mobile;
    String name,email,mobile;
    @override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_addinfo);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
    @override
    public void onClick(View view) {
    Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
    .setAction("Action", null).show();
    }
    });
    Name=(EditText)findViewById(R.id.name);
    Email=(EditText)findViewById(R.id.email);
    Mobile=(EditText)findViewById(R.id.mobile);
    }

    public void save(View view)
    {
    name=Name.getText().toString();
    email=Email.getText().toString();
    mobile=Mobile.getText().toString();
    BackgroundTask backgroundTask=new BackgroundTask();
    backgroundTask.execute(name,email,mobile);

    }
    class BackgroundTask extends AsyncTask<String,Void,String>
    {


    String add_info_url;

    @override
    protected String doInBackground(String... args) {
    String name,email,mobile;
    name=args[0];
    email=args[1];
    mobile=args[2];


    try {
    URL url=new URL(add_info_url);
    HttpURLConnection httpURLConnection=(HttpURLConnection)url.openConnection();
    httpURLConnection.setRequestMethod("POST");
    httpURLConnection.setDoOutput(true);
    OutputStream outputStream=httpURLConnection.getOutputStream();
    BufferedWriter bufferedWriter=new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8"));
    String data= URLEncoder.encode("name","UTF-8")+"="+URLEncoder.encode(name,"UTF-8")+"&"+
    URLEncoder.encode("email","UTF-8")+"="+URLEncoder.encode(email,"UTF-8")+"&"+
    URLEncoder.encode("mobile","UTF-8")+"="+URLEncoder.encode(mobile,"UTF-8")+"&";
    bufferedWriter.write(data);
    bufferedWriter.flush();
    bufferedWriter.close();
    outputStream.close();
    InputStream inputStream =httpURLConnection.getInputStream();
    inputStream.close();
    httpURLConnection.disconnect();
    return "one row inserted!!!";
    } catch (MalformedURLException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    return null;
    }

    @override
    protected void onPostExecute(String result) {


    Toast.makeText(getApplicationContext(),result,Toast.LENGTH_LONG).show();
    }

    @override
    protected void onPreExecute() {

    add_info_url="http://ashishkha123.byethost17.com/add_info.php";


    }

    @override
    protected void onProgressUpdate(Void... values) {
    super.onProgressUpdate(values);
    }
    }

    }





    sir please help me i had doubt
    i had made a free host account and i ruuning this code in android emulator or real device the data is not storing in my data base online.... i had made database with phpmy admin please help
     



    1. Download the Forums for Android™ app!


      Download

       
  2. The_Chief

    The_Chief Accept no imitations!
    VIP Member

    Hi! I moved your question to the Application Development Forum, where more experienced eyes can see it and help you :)
     
  3. Deleted User

    Deleted User Guest

    Couple of questions:-

    1. Did the PHP script on the server side receive the HTTP POST? Can you create some debug logging messages in the script?

    2. Is there anything in the Logcat output in Android Studio. i.e. did the code throw any exceptions?
     
Loading...

Share This Page

Loading...