Advertisement
Guest User

Untitled

a guest
May 9th, 2016
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.56 KB | None | 0 0
  1. package com.example.user.social;
  2.  
  3. import android.content.Intent;
  4. import android.os.AsyncTask;
  5. import android.os.Bundle;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.view.Window;
  10. import android.view.WindowManager;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import org.apache.http.HttpResponse;
  14. import org.apache.http.NameValuePair;
  15. import org.apache.http.client.HttpClient;
  16. import org.apache.http.client.entity.UrlEncodedFormEntity;
  17. import org.apache.http.client.methods.HttpPost;
  18. import org.apache.http.impl.client.DefaultHttpClient;
  19. import org.apache.http.message.BasicNameValuePair;
  20. import org.apache.http.util.EntityUtils;
  21.  
  22. import java.util.ArrayList;
  23. import java.util.List;
  24.  
  25. public class Register extends AppCompatActivity {
  26.  
  27. Button register;
  28. Button back;
  29. EditText username;
  30. EditText password;
  31. EditText email;
  32. EditText name;
  33.  
  34. @Override
  35. protected void onCreate(Bundle savedInstanceState) {
  36. super.onCreate(savedInstanceState);
  37. requestWindowFeature(Window.FEATURE_NO_TITLE);
  38. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  39. setContentView(R.layout.activity_register);
  40.  
  41. register = (Button) findViewById(R.id.register);
  42. back = (Button) findViewById(R.id.back);
  43. email = (EditText) findViewById(R.id.editText2);
  44. name = (EditText) findViewById(R.id.editText);
  45. username = (EditText) findViewById(R.id.user);
  46. password = (EditText) findViewById(R.id.pass);
  47.  
  48. back.setOnClickListener(new View.OnClickListener() {
  49. @Override
  50. public void onClick(View v) {
  51.  
  52. startActivity(new Intent(getApplicationContext(),Login.class));
  53.  
  54. }
  55. });
  56.  
  57. register.setOnClickListener(new View.OnClickListener() {
  58. @Override
  59. public void onClick(View v) {
  60. String user = username.getText().toString().trim();
  61. String pass = password.getText().toString().trim();
  62. String emaill = email.getText().toString().trim();
  63. String namee = name.getText().toString().trim();
  64. new RegisterInServer().execute(user,pass,emaill,namee);
  65. }
  66. });
  67.  
  68.  
  69. }
  70.  
  71. private class RegisterInServer extends AsyncTask<String,Void,Long>
  72. {
  73. @Override
  74. protected Long doInBackground(String... params) {
  75.  
  76. String username = params[0];
  77. String email = params[2];
  78. String name = params[3];
  79. String password = params[1];
  80.  
  81. HttpClient httpclient = new DefaultHttpClient();
  82. HttpPost httppost = new HttpPost("http://idoazulay.byethost16.com/phpcode.php");
  83.  
  84. try {
  85. // Add your data
  86. List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
  87. nameValuePairs.add(new BasicNameValuePair("name", "Name"));
  88. nameValuePairs.add(new BasicNameValuePair("username", "Username"));
  89. nameValuePairs.add(new BasicNameValuePair("email", "Idoazzz"));
  90. nameValuePairs.add(new BasicNameValuePair("password", "87426088"));
  91. httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  92.  
  93. // Execute HTTP Post Request
  94. HttpResponse response = httpclient.execute(httppost);
  95. String responseBody = EntityUtils.toString(response.getEntity());
  96. Log.d("Hey",responseBody);
  97.  
  98. } catch (Exception e) {
  99. e.printStackTrace();
  100.  
  101. // TODO Auto-generated catch block
  102. }
  103. return null;
  104.  
  105. }
  106.  
  107. @Override
  108. protected void onPostExecute(Long result) {
  109. }
  110. }
  111.  
  112. <?xml version="1.0" encoding="utf-8"?>
  113. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  114. xmlns:tools="http://schemas.android.com/tools"
  115. android:layout_width="match_parent"
  116. android:layout_height="match_parent"
  117. android:paddingBottom="@dimen/activity_vertical_margin"
  118. android:paddingLeft="@dimen/activity_horizontal_margin"
  119. android:paddingRight="@dimen/activity_horizontal_margin"
  120. android:paddingTop="@dimen/activity_vertical_margin"
  121. tools:context="com.example.user.social.Register"
  122. android:background="#fff">
  123.  
  124. <LinearLayout
  125. android:orientation="vertical"
  126. android:layout_width="match_parent"
  127. android:layout_height="match_parent"
  128. android:layout_alignParentRight="true"
  129. android:layout_alignParentEnd="true"
  130. android:layout_below="@+id/user"
  131. android:weightSum="1">
  132.  
  133. <EditText
  134. android:layout_width="match_parent"
  135. android:layout_height="wrap_content"
  136. android:id="@+id/user"
  137. android:layout_alignParentTop="true"
  138. android:layout_marginTop="50dp"
  139. android:layout_alignParentLeft="true"
  140. android:layout_alignParentStart="true"
  141. android:layout_alignParentRight="true"
  142. android:layout_alignParentEnd="true"
  143. android:inputType="text"
  144. android:text="aaa"
  145. android:textAlignment="center"
  146. android:textColor="#9e9e9e"
  147. android:layout_weight="0.15" />
  148.  
  149. <EditText
  150. android:layout_width="match_parent"
  151. android:layout_height="wrap_content"
  152. android:id="@+id/pass"
  153. android:layout_alignParentTop="true"
  154. android:layout_marginTop="20dp"
  155. android:layout_alignParentLeft="true"
  156. android:layout_alignParentStart="true"
  157. android:layout_alignParentRight="true"
  158. android:layout_alignParentEnd="true"
  159. android:inputType="text"
  160. android:text="aaa"
  161. android:textAlignment="center"
  162. android:textColor="#9e9e9e"
  163. android:layout_weight="0.15" />
  164.  
  165. <EditText
  166. android:layout_width="match_parent"
  167. android:layout_height="wrap_content"
  168. android:id="@+id/editText"
  169. android:layout_alignParentTop="true"
  170. android:layout_marginTop="20dp"
  171. android:layout_alignParentLeft="true"
  172. android:layout_alignParentStart="true"
  173. android:layout_alignParentRight="true"
  174. android:layout_alignParentEnd="true"
  175. android:inputType="text"
  176. android:text="aaa"
  177. android:textAlignment="center"
  178. android:textColor="#9e9e9e"
  179. android:layout_weight="0.15"
  180. android:layout_gravity="center_horizontal" />
  181.  
  182. <EditText
  183. android:layout_width="match_parent"
  184. android:layout_height="wrap_content"
  185. android:id="@+id/editText2"
  186. android:layout_alignParentTop="true"
  187. android:layout_marginTop="20dp"
  188. android:layout_alignParentLeft="true"
  189. android:layout_alignParentStart="true"
  190. android:layout_alignParentRight="true"
  191. android:layout_alignParentEnd="true"
  192. android:inputType="text"
  193. android:text="aaa"
  194. android:textAlignment="center"
  195. android:textColor="#9e9e9e"
  196. android:layout_weight="0.15"
  197. android:layout_gravity="center_horizontal" />
  198.  
  199. <Button
  200. android:layout_width="match_parent"
  201. android:layout_height="wrap_content"
  202. android:text="חזרה"
  203. android:id="@+id/back"
  204. android:layout_gravity="center_horizontal"
  205. android:layout_weight="0.05"
  206. android:layout_marginTop="20dp"
  207. android:background="#58abff"
  208. android:textColor="#fff" />
  209.  
  210. <Button
  211. android:layout_width="match_parent"
  212. android:layout_height="wrap_content"
  213. android:text="הרשמה"
  214. android:id="@+id/register"
  215. android:layout_gravity="center_horizontal"
  216. android:layout_weight="0.05"
  217. android:layout_marginTop="0dp"
  218. android:background="#2e8ece"
  219. android:textColor="#fff" />
  220.  
  221. <Button
  222. android:layout_width="match_parent"
  223. android:layout_height="8dp"
  224. android:id="@+id/button"
  225. android:layout_gravity="center_horizontal"
  226. android:layout_marginTop="0dp"
  227. android:background="#196ca3"
  228. android:textColor="#fff" />
  229.  
  230. </LinearLayout>
  231.  
  232. <?php
  233. $servername = "sql207.byethost16.com";
  234. $username = "b16_18022237";
  235. $password = "87426088";
  236. $dbname = "b16_18022237_test";
  237.  
  238. // Create connection
  239. $conn = new mysqli($servername, $username, $password, $dbname);
  240. // Check connection
  241. if ($conn->connect_error) {
  242. die("Connection failed: " . $conn->connect_error);
  243. }
  244.  
  245.  
  246.  
  247. $name=$_POST['name'];
  248. $email = $_POST['username'];
  249. $username = $_POST['email'];
  250. $password = $_POST['password'];
  251.  
  252.  
  253. $sql = "INSERT INTO users (id,name,username,email,password)
  254. VALUES (DEFAULT,'{$name}','{$username}','{$email}','{$password}')";
  255.  
  256. if ($conn->query($sql) === TRUE) {
  257. echo "New record created successfully";
  258. } else {
  259. echo "Error: " . $sql . "<br>" . $conn->error;
  260. }
  261.  
  262. $conn->close();
  263. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement