Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.harshitbatra.hammertime;
- import android.os.AsyncTask;
- import android.util.Log;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.io.OutputStreamWriter;
- import java.io.UnsupportedEncodingException;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLEncoder;
- import java.util.HashMap;
- import java.util.Map;
- import javax.net.ssl.HttpsURLConnection;
- /**
- * Created by Harshit Batra on 06-07-2016.
- */
- public class Signupasync extends AsyncTask<String, Void, String>
- {
- String username,phone,address,email,password;
- String url;
- private postexecutelistener myListener;
- public Signupasync(postexecutelistener pel,String url,String username, String phone,String address,String email,String password )
- {
- myListener = pel;
- this.url = url;
- this.username = username;
- this.phone = phone;
- this.address = address;
- this.email = email;
- this.password = password;
- }
- public interface postexecutelistener
- {
- public void postexecutedone(String str);
- }
- public String connect()
- {
- HashMap<String,String> hash = new HashMap<>(6);
- hash.put("usernamekey",username);
- hash.put("phonekey",phone);
- hash.put("addresskey",address);
- hash.put("emailkey",email);
- hash.put("passwordkey",password);
- return performPostCall(url,hash);
- }
- public String performPostCall(String requestURL, HashMap<String, String> postDataParams)
- {
- URL url;
- String response = "";
- try
- {
- url = new URL(requestURL);
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setReadTimeout(15000);
- conn.setConnectTimeout(15000);
- conn.setRequestMethod("POST");
- conn.setDoInput(true);
- conn.setDoOutput(true);
- OutputStream os = conn.getOutputStream();
- BufferedWriter writer = new BufferedWriter(
- new OutputStreamWriter(os, "UTF-8"));
- writer.write(getPostDataString(postDataParams));
- writer.flush();
- writer.close();
- os.close();
- int responseCode = conn.getResponseCode();
- if (responseCode == HttpsURLConnection.HTTP_OK)
- {
- String line;
- BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- while ((line = br.readLine()) != null)
- {
- response += line;
- }
- }
- else
- {
- response = "";
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- return response;
- }
- private String getPostDataString(HashMap<String, String> params) throws UnsupportedEncodingException
- {
- StringBuilder result = new StringBuilder();
- boolean first = true;
- for (Map.Entry<String, String> entry : params.entrySet())
- {
- if (first)
- first = false;
- else
- result.append("&");
- result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
- result.append("=");
- result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
- }
- Log.e("dsasd", "getPostDataString: " + result);
- return result.toString();
- }
- @Override
- protected String doInBackground(String... para)
- {
- return connect();
- }
- @Override
- protected void onPostExecute(String str)
- {
- super.onPostExecute(str);
- Log.d("jsdk", "String from signup.php " + str);
- myListener.postexecutedone(str);
- }
- }
- $con = mysqli_connect("mysql.hostinger.in","u626717580_batra","hb99960","u626717580_mydb");
- if($con)
- {
- $username = $_POST['usernamekey'];
- $phone = $_POST['phonekey'];
- $address = $_POST['addresskey'];
- $email = $_POST['emailkey'];
- $password = $_POST['passwordkey'];
- $sql = "INSERT INTO `u626717580_mydb`.`signup` (
- `username` ,
- `phone` ,
- `address` ,
- `email` ,
- `password`
- )
- VALUES (
- '$username', '$phone', '$address', '$email', '$password'
- );
- ";
- if($username)
- {
- if(mysqli_query($con,$sql) )
- echo "true";
- else
- echo "false";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement