Android程式碼部分如下
package
com.example.user.myapplication;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.os.Looper;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

new Thread(new Runnable(){

@Override
public void run() {
Looper.prepare();
// TODO Auto-generated method stub
HttpClient client = new DefaultHttpClient();
HttpGet myget = new HttpGet("http://改成你主機的IP/login2.php?age=25");
try {
HttpResponse response = client.execute(myget);

} catch (Exception e) {

e.printStackTrace();
}
Looper.loop();
}}).start();
}
}

PHP程式碼部分如下

<?php
$getval = $_GET['age'];
echo $getval;
$link=mysql_connect("localhost","test123","test123");
mysql_query("SET NAMES utf8");
mysql_select_db("dbname",$link);
$sql=mysql_query("insert into tablename(age) values('$getval')",$link);
mysql_close();
?>

以上完成
arrow
arrow
    創作者介紹
    創作者 痞客興 的頭像
    痞客興

    痞客興的部落格

    痞客興 發表在 痞客邦 留言(0) 人氣()