Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. <?php
  2.  
  3. $con=mysql_connect('localhost','root','');
  4. mysql_select_db('hellodb',$con);
  5.  
  6. $name = $_POST['name'];
  7. $age = $_POST['age'];
  8. $email = $_POST['email'];
  9.  
  10. $mysql_query("insert into user_detail(name,age,email) values('{$name}','{$age}','{$email}')");
  11.  
  12. ?>
  13.  
  14. public class MainActivity extends ActionBarActivity {
  15.  
  16. EditText eName,eAge,eEmail;
  17. Button inButton;
  18. InputStream is=null;
  19. @Override
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. StrictMode.ThreadPolicy tp = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  23. StrictMode.setThreadPolicy(tp);
  24. setContentView(R.layout.main);
  25.  
  26. eName= (EditText) findViewById(R.id.etname);
  27. eAge= (EditText) findViewById(R.id.etage);
  28. eEmail= (EditText) findViewById(R.id.etemail);
  29. inButton=(Button)findViewById(R.id.ibutton);
  30.  
  31. inButton.setOnClickListener(new View.OnClickListener() {
  32. @Override
  33. public void onClick(View v) {
  34. String name=""+eName.getText();
  35. String age=""+eAge.getText();
  36. String email=""+eEmail.getText();
  37.  
  38. List<NameValuePair> nameValuePairs=new ArrayList<NameValuePair>(1);
  39. nameValuePairs.add(new BasicNameValuePair("name","name"));
  40. nameValuePairs.add(new BasicNameValuePair("age","age"));
  41. nameValuePairs.add(new BasicNameValuePair("email","email"));
  42.  
  43. try {
  44. HttpClient httpClient=new DefaultHttpClient();
  45. HttpPost httpPost=new HttpPost("http://10.0.2.2:8888/demo/getdata.php");
  46. httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  47. HttpResponse response=httpClient.execute(httpPost);
  48.  
  49. HttpEntity entity=response.getEntity();
  50.  
  51. is=entity.getContent();
  52.  
  53. } catch (ClientProtocolException e) {
  54. Log.e("ClientProtocol","LogTag");
  55. e.printStackTrace();
  56. }catch (IOException e) {
  57. Log.e("LogTag","IOException");
  58. e.printStackTrace();
  59. }
  60. }
  61. });
  62. }
  63.  
  64. }
  65.  
  66. <EditText
  67. android:id="@+id/etname"
  68. android:hint="Enter Your Name"
  69. android:textAlignment="center"
  70. android:layout_width="fill_parent"
  71. android:layout_height="wrap_content" />
  72.  
  73. <EditText
  74. android:id="@+id/etage"
  75. android:hint="Enter Your Age"
  76. android:layout_width="fill_parent"
  77. android:layout_height="wrap_content" />
  78. <EditText
  79. android:id="@+id/etemail"
  80. android:hint="Enter Your Email"
  81. android:layout_width="fill_parent"
  82. android:layout_height="wrap_content" />
  83.  
  84. <Button
  85. android:layout_width="169dp"
  86. android:layout_height="wrap_content"
  87. android:text="Insert"
  88. android:id="@+id/ibutton"
  89. android:layout_gravity="center_horizontal" />
  90.  
  91. $dbtype = "mysql";
  92. $dbhost = "localhost";
  93. $dbname = "hellodb";
  94. $dbuser = "root";
  95. $dbpass = "";
  96.  
  97. $name = $_POST['name'];
  98. $age = $_POST['age'];
  99. $email = $_POST['email'];
  100.  
  101. // database connection
  102. $conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
  103.  
  104. $sql = "INSERT INTO user_detail(name,age,email) VALUES (:name,:age,:email)";
  105. $q = $conn->prepare($sql);
  106.  
  107. $q->execute(array(':name'=>$name,
  108. ':age'=>$age,
  109. ':email'=>$email));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement