Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SyncTask extends AsyncTask<String,Void,String> {
- Context ctx;
- SyncTask(Context ctx){
- this.ctx=ctx;
- }
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
- @Override
- protected String doInBackground(String... params) {
- String URL = "http://vlsiptv.tk/reg.php";
- String name = params [0];
- String surname = params [1];
- String password = params [2];
- String type = params [3];
- try {
- URL url = new URL(URL);
- HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
- httpURLConnection.setRequestMethod("POST");
- httpURLConnection.setDoOutput(true);
- OutputStream OS = httpURLConnection.getOutputStream();
- BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(OS, "UTF-8"));
- String data = URLEncoder.encode("name","UTF-8")+ "=" + URLEncoder.encode(name,"UTF-8")+"&"+
- URLEncoder.encode("surname","UTF-8")+ "=" + URLEncoder.encode(surname,"UTF-8")+"&"+
- URLEncoder.encode("password","UTF-8")+ "=" + URLEncoder.encode(password,"UTF-8")+"&"+
- URLEncoder.encode("type","UTF-8")+ "=" + URLEncoder.encode(type,"UTF-8");
- bufferedWriter.write(data);
- bufferedWriter.flush();
- bufferedWriter.close();
- OS.close();
- InputStream IS = httpURLConnection.getInputStream();
- IS.close();
- return "Done!";
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return "Error";
- }
- @Override
- protected void onProgressUpdate(Void... values) {
- super.onProgressUpdate(values);
- }
- @Override
- protected void onPostExecute(String result) {
- Toast.makeText(ctx,result,Toast.LENGTH_LONG).show();
- }
- }
- type = "null";
- name = et_name.getText().toString();
- surname= et_surname.getText().toString();
- password = et_password.getText().toString();
- anhat = (RadioButton) findViewById(R.id.radio_anhat);
- kazmakerputyun = (RadioButton) findViewById(R.id.radio_kazmakerputyun);
- masnaget = (RadioButton) findViewById(R.id.radio_masnaget);
- if(anhat.isChecked()) type="Ա";
- if(kazmakerputyun.isChecked()) type="Բ";
- if(masnaget.isChecked()) type="Գ";
- SyncTask SyncTask = new SyncTask(this);
- SyncTask.execute(name,surname,password,type);
- <?php
- $servername = "db4free.net";
- $username = "stepvaruzhan";
- $password = "qwerty1250";
- $dbname = "registers";
- $name =$_POST["name"];
- $surname = $_POST["surname"];
- $password=$_POST["password"];
- $type=$_POST["type"];
- $conn = new mysqli($servername, $username, $password, $dbname);
- $sql = "INSERT INTO reg (name, surname, password,type) VALUES ('$name', '$surname', '$password','$type')";
- if ($conn->query($sql) === TRUE) {
- // echo "New record created successfully";
- } else {
- // echo "Error: " . $sql . "<br>" . $conn->error;
- }
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement