Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.user.social;
- import android.content.Intent;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.util.Log;
- import android.view.View;
- import android.view.Window;
- import android.view.WindowManager;
- import android.widget.Button;
- import android.widget.EditText;
- import org.apache.http.HttpResponse;
- import org.apache.http.NameValuePair;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.entity.UrlEncodedFormEntity;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.apache.http.message.BasicNameValuePair;
- import org.apache.http.util.EntityUtils;
- import java.util.ArrayList;
- import java.util.List;
- public class Register extends AppCompatActivity {
- Button register;
- Button back;
- EditText username;
- EditText password;
- EditText email;
- EditText name;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_register);
- register = (Button) findViewById(R.id.register);
- back = (Button) findViewById(R.id.back);
- email = (EditText) findViewById(R.id.editText2);
- name = (EditText) findViewById(R.id.editText);
- username = (EditText) findViewById(R.id.user);
- password = (EditText) findViewById(R.id.pass);
- back.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- startActivity(new Intent(getApplicationContext(),Login.class));
- }
- });
- register.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- String user = username.getText().toString().trim();
- String pass = password.getText().toString().trim();
- String emaill = email.getText().toString().trim();
- String namee = name.getText().toString().trim();
- new RegisterInServer().execute(user,pass,emaill,namee);
- }
- });
- }
- private class RegisterInServer extends AsyncTask<String,Void,Long>
- {
- @Override
- protected Long doInBackground(String... params) {
- String username = params[0];
- String email = params[2];
- String name = params[3];
- String password = params[1];
- HttpClient httpclient = new DefaultHttpClient();
- HttpPost httppost = new HttpPost("http://idoazulay.byethost16.com/phpcode.php");
- try {
- // Add your data
- List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
- nameValuePairs.add(new BasicNameValuePair("name", "Name"));
- nameValuePairs.add(new BasicNameValuePair("username", "Username"));
- nameValuePairs.add(new BasicNameValuePair("email", "Idoazzz"));
- nameValuePairs.add(new BasicNameValuePair("password", "87426088"));
- httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
- // Execute HTTP Post Request
- HttpResponse response = httpclient.execute(httppost);
- String responseBody = EntityUtils.toString(response.getEntity());
- Log.d("Hey",responseBody);
- } catch (Exception e) {
- e.printStackTrace();
- // TODO Auto-generated catch block
- }
- return null;
- }
- @Override
- protected void onPostExecute(Long result) {
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context="com.example.user.social.Register"
- android:background="#fff">
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true"
- android:layout_below="@+id/user"
- android:weightSum="1">
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/user"
- android:layout_alignParentTop="true"
- android:layout_marginTop="50dp"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true"
- android:inputType="text"
- android:text="aaa"
- android:textAlignment="center"
- android:textColor="#9e9e9e"
- android:layout_weight="0.15" />
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/pass"
- android:layout_alignParentTop="true"
- android:layout_marginTop="20dp"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true"
- android:inputType="text"
- android:text="aaa"
- android:textAlignment="center"
- android:textColor="#9e9e9e"
- android:layout_weight="0.15" />
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/editText"
- android:layout_alignParentTop="true"
- android:layout_marginTop="20dp"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true"
- android:inputType="text"
- android:text="aaa"
- android:textAlignment="center"
- android:textColor="#9e9e9e"
- android:layout_weight="0.15"
- android:layout_gravity="center_horizontal" />
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/editText2"
- android:layout_alignParentTop="true"
- android:layout_marginTop="20dp"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true"
- android:inputType="text"
- android:text="aaa"
- android:textAlignment="center"
- android:textColor="#9e9e9e"
- android:layout_weight="0.15"
- android:layout_gravity="center_horizontal" />
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="חזרה"
- android:id="@+id/back"
- android:layout_gravity="center_horizontal"
- android:layout_weight="0.05"
- android:layout_marginTop="20dp"
- android:background="#58abff"
- android:textColor="#fff" />
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="הרשמה"
- android:id="@+id/register"
- android:layout_gravity="center_horizontal"
- android:layout_weight="0.05"
- android:layout_marginTop="0dp"
- android:background="#2e8ece"
- android:textColor="#fff" />
- <Button
- android:layout_width="match_parent"
- android:layout_height="8dp"
- android:id="@+id/button"
- android:layout_gravity="center_horizontal"
- android:layout_marginTop="0dp"
- android:background="#196ca3"
- android:textColor="#fff" />
- </LinearLayout>
- <?php
- $servername = "sql207.byethost16.com";
- $username = "b16_18022237";
- $password = "87426088";
- $dbname = "b16_18022237_test";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $name=$_POST['name'];
- $email = $_POST['username'];
- $username = $_POST['email'];
- $password = $_POST['password'];
- $sql = "INSERT INTO users (id,name,username,email,password)
- VALUES (DEFAULT,'{$name}','{$username}','{$email}','{$password}')";
- 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