Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将android连接到免费webhost中的服务器_Php_Android_Mysql - Fatal编程技术网

Php 将android连接到免费webhost中的服务器

Php 将android连接到免费webhost中的服务器,php,android,mysql,Php,Android,Mysql,我可以将android应用程序连接到免费webhost(www.000webhost.com)中的服务器,并在android和mysql数据库以及php之间发送数据吗 如果是这样的话,有人能给我一些指导吗?是的,例如,在获取数据方面,您可能会遇到一些小问题 PHP: 从php获取数据并在listview中显示的完整代码: 首先,您需要将添加到连接internet的AndroidManifest.xml AndroidManifest.xml: <?xml version="1.0" en

我可以将android应用程序连接到免费webhost(www.000webhost.com)中的服务器,并在android和mysql数据库以及php之间发送数据吗


如果是这样的话,有人能给我一些指导吗?

是的,例如,在获取数据方面,您可能会遇到一些小问题

PHP:


从php获取数据并在listview中显示的完整代码:

首先,您需要将
添加到连接internet的AndroidManifest.xml

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ir.sheikhoo.freehost"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <!--  Internet Permissions -->
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
并将listview添加到
活动\u main.xml

<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="ir.sheikhoo.freehost.MainActivity" >


    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" >
    </ListView>

</RelativeLayout>
图片:

要将数据发送到MySQL,首先要编写PHP代码将数据插入MySQL

(»我添加消息以显示应用程序中发生的情况)

PHP:

然后创建新活动并添加
EditText
按钮

活动_send.xml:

<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="ir.sheikhoo.freehost.SendActivity" >

    <EditText
        android:id="@+id/Name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/textView1"
        android:layout_marginLeft="14dp"
        android:layout_toRightOf="@+id/textView1"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Name :" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/Name"
        android:layout_marginTop="21dp"
        android:text="Send" />

</RelativeLayout>

SendActivity.java:

public class SendActivity extends ActionBarActivity {

    EditText ed_name;

    String myJSON;

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

        ed_name=(EditText) findViewById(R.id.Name);
        Button btn=(Button) findViewById(R.id.button1);

        btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                if(!ed_name.getText().toString().matches("")){
                    SendData();
                }else{
                    Toast.makeText(getBaseContext(),"Name NULL",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    public void SendData(){
        class GetDataJSON extends AsyncTask<String, Void, String>{

            private ProgressDialog Dialog;
            private InputStream is = null;
            private String url = "http://sheikhoo.net46.net/sendname.php";
            private String page_output = "";

            @Override
            protected void onPreExecute(){
                super.onPreExecute();
                Dialog = new ProgressDialog(SendActivity.this);
                Dialog.setTitle("Contacting Servers");
                Dialog.setMessage("Logging in ...");
                Dialog.setIndeterminate(false);
                Dialog.setCancelable(true);
                Dialog.show();
            }

            @Override
            protected String doInBackground(String... args) {

                try {
                        // Building Parameters
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("Name", ed_name.getText().toString()));
                // defaultHttpClient
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(params));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                Toast.makeText(getBaseContext(),"Error To Connect",
                    Toast.LENGTH_SHORT).show();
            } catch (ClientProtocolException e) {
                e.printStackTrace();
                Toast.makeText(getBaseContext(),"Error To Connect",
                    Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(getBaseContext(),"Error To Connect",
                    Toast.LENGTH_SHORT).show();
            }
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
                StringBuilder sb = new StringBuilder();

                String line = null;
                while ((line = reader.readLine()) != null)
                {
                    sb.append(line + "\n");
                }
                is.close();
                page_output = sb.toString();

                Log.i("LOG", "page_output --> " + page_output); ///<--------------------------|
            /*****************remove script***********************/
            String s = page_output;
            int position = s.indexOf("<"); 

            s=s.substring(0, position - 1);

            page_output=s;
            /****************************************************/
            } catch (Exception e) {
                Log.e("Buffer Error", "Error converting result " + e.toString());
                Toast.makeText(getBaseContext(),"Buffer Error",
                    Toast.LENGTH_SHORT).show();
            }

            return page_output;
        }

            @Override
            protected void onPostExecute(String result){
                Dialog.dismiss();

                Log.i("LOG", " onPostExecute -> " + result );
                myJSON=result;
                Log.i("LOG", "myJSON" + myJSON);

                if(myJSON.trim().equals("executed")){
                    Toast.makeText(getBaseContext(),"Name Save in DB",
                        Toast.LENGTH_SHORT).show();
                    ed_name.setText("");
                }else{
                    Toast.makeText(getBaseContext(),"Error Name don't Save in DB",
                        Toast.LENGTH_SHORT).show();
            }
            }
        }
        GetDataJSON g = new GetDataJSON();
        Log.i("LOG", " GetDataJSON " );
        g.execute();
    }
}
公共类SendActivity扩展了ActionBarActivity{
编辑文本编辑名称;
字符串myJSON;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_send);
ed_name=(EditText)findViewById(R.id.name);
按钮btn=(按钮)findViewById(R.id.button1);
btn.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图arg0){
//TODO自动生成的方法存根
如果(!ed_name.getText().toString()匹配(“”){
SendData();
}否则{
Toast.makeText(getBaseContext(),“Name NULL”,
吐司。长度(短)。show();
}
}
});
}
public void SendData(){
类GetDataJSON扩展了AsyncTask{
私人对话;
私有InputStream为空;
专用字符串url=”http://sheikhoo.net46.net/sendname.php";
私有字符串页_输出=”;
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
Dialog=新建ProgressDialog(SendActivity.this);
对话框.setTitle(“联系服务器”);
setMessage(“登录…”);
Dialog.setUndeterminate(false);
对话框。可设置可取消(true);
Dialog.show();
}
@凌驾
受保护的字符串doInBackground(字符串…args){
试一试{
//建筑参数
List params=new ArrayList();
add(新的BasicNameValuePair(“Name”,ed_Name.getText().toString());
//defaultHttpClient
DefaultHttpClient httpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(url);
setEntity(新的UrlEncodedFormEntity(参数));
HttpResponse HttpResponse=httpClient.execute(httpPost);
HttpEntity HttpEntity=httpResponse.getEntity();
is=httpEntity.getContent();
}捕获(不支持的编码异常e){
e、 printStackTrace();
Toast.makeText(getBaseContext(),“连接错误”,
吐司。长度(短)。show();
}捕获(客户端协议例外e){
e、 printStackTrace();
Toast.makeText(getBaseContext(),“连接错误”,
吐司。长度(短)。show();
}捕获(IOE异常){
e、 printStackTrace();
Toast.makeText(getBaseContext(),“连接错误”,
吐司。长度(短)。show();
}
试一试{
BufferedReader reader=新的BufferedReader(新的InputStreamReader(is,“UTF-8”),8;
StringBuilder sb=新的StringBuilder();
字符串行=null;
而((line=reader.readLine())!=null)
{
sb.追加(第+行“\n”);
}
is.close();
page_output=sb.toString();

Log.i(“Log”,“page_output-->”+page_output);//是的,例如,在获取数据时可能会遇到一些小问题

PHP:


从php获取数据并在listview中显示的完整代码:

首先,您需要将
添加到连接internet的AndroidManifest.xml

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ir.sheikhoo.freehost"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <!--  Internet Permissions -->
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
并将listview添加到
活动\u main.xml

<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="ir.sheikhoo.freehost.MainActivity" >


    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" >
    </ListView>

</RelativeLayout>
图片:

要将数据发送到MySQL,首先要编写PHP代码将数据插入MySQL

(»我添加消息以显示应用程序中发生的情况)

PHP:

然后创建新活动并添加
EditText
按钮

活动_send.xml:

<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="ir.sheikhoo.freehost.SendActivity" >

    <EditText
        android:id="@+id/Name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/textView1"
        android:layout_marginLeft="14dp"
        android:layout_toRightOf="@+id/textView1"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Name :" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/Name"
        android:layout_marginTop="21dp"
        android:text="Send" />

</RelativeLayout>

SendActivity.java:

public class SendActivity extends ActionBarActivity {

    EditText ed_name;

    String myJSON;

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

        ed_name=(EditText) findViewById(R.id.Name);
        Button btn=(Button) findViewById(R.id.button1);

        btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                if(!ed_name.getText().toString().matches("")){
                    SendData();
                }else{
                    Toast.makeText(getBaseContext(),"Name NULL",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    public void SendData(){
        class GetDataJSON extends AsyncTask<String, Void, String>{

            private ProgressDialog Dialog;
            private InputStream is = null;
            private String url = "http://sheikhoo.net46.net/sendname.php";
            private String page_output = "";

            @Override
            protected void onPreExecute(){
                super.onPreExecute();
                Dialog = new ProgressDialog(SendActivity.this);
                Dialog.setTitle("Contacting Servers");
                Dialog.setMessage("Logging in ...");
                Dialog.setIndeterminate(false);
                Dialog.setCancelable(true);
                Dialog.show();
            }

            @Override
            protected String doInBackground(String... args) {

                try {
                        // Building Parameters
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("Name", ed_name.getText().toString()));
                // defaultHttpClient
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(params));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                Toast.makeText(getBaseContext(),"Error To Connect",
                    Toast.LENGTH_SHORT).show();
            } catch (ClientProtocolException e) {
                e.printStackTrace();
                Toast.makeText(getBaseContext(),"Error To Connect",
                    Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(getBaseContext(),"Error To Connect",
                    Toast.LENGTH_SHORT).show();
            }
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
                StringBuilder sb = new StringBuilder();

                String line = null;
                while ((line = reader.readLine()) != null)
                {
                    sb.append(line + "\n");
                }
                is.close();
                page_output = sb.toString();

                Log.i("LOG", "page_output --> " + page_output); ///<--------------------------|
            /*****************remove script***********************/
            String s = page_output;
            int position = s.indexOf("<"); 

            s=s.substring(0, position - 1);

            page_output=s;
            /****************************************************/
            } catch (Exception e) {
                Log.e("Buffer Error", "Error converting result " + e.toString());
                Toast.makeText(getBaseContext(),"Buffer Error",
                    Toast.LENGTH_SHORT).show();
            }

            return page_output;
        }

            @Override
            protected void onPostExecute(String result){
                Dialog.dismiss();

                Log.i("LOG", " onPostExecute -> " + result );
                myJSON=result;
                Log.i("LOG", "myJSON" + myJSON);

                if(myJSON.trim().equals("executed")){
                    Toast.makeText(getBaseContext(),"Name Save in DB",
                        Toast.LENGTH_SHORT).show();
                    ed_name.setText("");
                }else{
                    Toast.makeText(getBaseContext(),"Error Name don't Save in DB",
                        Toast.LENGTH_SHORT).show();
            }
            }
        }
        GetDataJSON g = new GetDataJSON();
        Log.i("LOG", " GetDataJSON " );
        g.execute();
    }
}
公共类SendActivity扩展了ActionBarActivity{
编辑文本编辑名称;
字符串myJSON;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_send);
ed_name=(EditText)findViewById(R.id.name);
按钮btn=(按钮)findViewById(R.id.button1);
btn.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图arg0){
//TODO自动生成的方法存根
如果(!ed_name.getText().toString()匹配(“”){
SendData();
}否则{
Toast.makeText(getBaseContext(),“Name NULL”,
吐司。长度(短)。show();
}
}
});
}
public void SendData(){
类GetDataJSON扩展了AsyncTask{
私人对话;
私有InputStream为空;
专用字符串url=”http://sheikhoo.net4
public class MainActivity extends ActionBarActivity {

    String myJSON;

    private static final String TAG_ALLNAME="allname";
    private static final String TAG_ID = "id";
    private static final String TAG_NAME = "Name";

    JSONArray jname = null;

    ArrayList<HashMap<String, String>> nameList;

    ListView list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.i("LOG", "Start <-- ");
        list = (ListView) findViewById(R.id.listView);
        nameList = new ArrayList<HashMap<String,String>>();
        Log.i("LOG", "GetData <-- ");

        GetData();
    }

    public void GetData(){
        class GetDataJSON extends AsyncTask<String, Void, String>{

            @Override
            protected String doInBackground(String... params) {
                DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
                HttpPost httppost = new HttpPost("http://sheikhoo.net46.net/getname.php");
                Log.i("LOG", "HttpPost -> getname.php");
                // Depends on your web service
                httppost.setHeader("Content-type", "application/json");

                InputStream inputStream = null;
                String result = null;
                Log.i("LOG", inputStream + "," + result);
                try {
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity entity = response.getEntity();

                    inputStream = entity.getContent();
                    // json is UTF-8 by default
                    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
                    StringBuilder sb = new StringBuilder();

                    String line = null;
                    while ((line = reader.readLine()) != null)
                    {
                        sb.append(line + "\n");
                    }
                    result = sb.toString();
                    Log.i("LOG", result);
                } catch (Exception e) {
                    // Oops
                    Log.i("LOG", " error ");
                }
                finally {
                    try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
                }
                Log.i("LOG", " result: " + result);
                /*****************remove script***********************/
                String s = result;
                int position = s.indexOf("}]}"); 

                s=s.substring(0, position + 3);
                /****************************************************/
                return s;
            }

            @Override
            protected void onPostExecute(String result){
                Log.i("LOG", " onPostExecute -> " + result );
                myJSON=result;
                Log.i("LOG", "myJSON" + myJSON);
                //
                ShowNameList();
            }
        }
        GetDataJSON g = new GetDataJSON();
        Log.i("LOG", " GetDataJSON " );
        g.execute();
    }

    protected void ShowNameList(){
        try {
            Log.i("LOG", " showList " );
            //if(myJSON!=null){
                JSONObject jsonObj = new JSONObject(myJSON);
                jname = jsonObj.getJSONArray(TAG_ALLNAME);

                for(int i=0;i<jname.length();i++){
                    JSONObject c = jname.getJSONObject(i);
                    String id = c.getString(TAG_ID);
                    String name = c.getString(TAG_NAME);

                    Log.i("Ekhteraat app ControlPanel", id);

                    HashMap<String,String> lname = new HashMap<String,String>();

                    lname.put(TAG_ID,id);
                    lname.put(TAG_NAME,name);

                    nameList.add(lname);
                //}

                    Log.i("LOG", "Name -> " + id + " " +  name);
                    //setNewNews;
                    ;

                    ListAdapter adapter = new SimpleAdapter(
                            MainActivity.this, nameList, R.layout.list_item,
                            new String[]{TAG_ID,TAG_NAME},
                            new int[]{R.id.id, R.id.name}
                    );
                    list.setAdapter(adapter);
                }


        } catch (JSONException e) {
            e.printStackTrace();
        }

    }
}
<?php
header("Content-type: application/json; charset=utf-8");
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');

$hostname='mysql2.000webhost.com';
$username='a3067857_admin';
$password='xxxxxxxxx';

try {

    $dbh=new PDO("mysql:host=$hostname;dbname=a7769372_db;charset=utf8mb4",$username,$password);


    /*** QUERY ****/

    $statement = $dbh->prepare("INSERT INTO a7769372_db.my_table (name) VALUES (:Name);");

    if ($statement->execute(array(':Name' => $_POST['Name']))) {
        echo "executed";
    } else {
        echo "not executed";
    }

    /*** close connection ***/
    $dbh=null;

}catch(PDOException $e) {
 echo $e->getMessage();
}
?> 
CREATE TABLE my_table
(
    id int NOT NULL AUTO_INCREMENT,
    name varchar(255) NOT NULL,
    PRIMARY KEY (id)
)
<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="ir.sheikhoo.freehost.SendActivity" >

    <EditText
        android:id="@+id/Name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/textView1"
        android:layout_marginLeft="14dp"
        android:layout_toRightOf="@+id/textView1"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Name :" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/Name"
        android:layout_marginTop="21dp"
        android:text="Send" />

</RelativeLayout>
public class SendActivity extends ActionBarActivity {

    EditText ed_name;

    String myJSON;

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

        ed_name=(EditText) findViewById(R.id.Name);
        Button btn=(Button) findViewById(R.id.button1);

        btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                if(!ed_name.getText().toString().matches("")){
                    SendData();
                }else{
                    Toast.makeText(getBaseContext(),"Name NULL",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    public void SendData(){
        class GetDataJSON extends AsyncTask<String, Void, String>{

            private ProgressDialog Dialog;
            private InputStream is = null;
            private String url = "http://sheikhoo.net46.net/sendname.php";
            private String page_output = "";

            @Override
            protected void onPreExecute(){
                super.onPreExecute();
                Dialog = new ProgressDialog(SendActivity.this);
                Dialog.setTitle("Contacting Servers");
                Dialog.setMessage("Logging in ...");
                Dialog.setIndeterminate(false);
                Dialog.setCancelable(true);
                Dialog.show();
            }

            @Override
            protected String doInBackground(String... args) {

                try {
                        // Building Parameters
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("Name", ed_name.getText().toString()));
                // defaultHttpClient
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(params));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                Toast.makeText(getBaseContext(),"Error To Connect",
                    Toast.LENGTH_SHORT).show();
            } catch (ClientProtocolException e) {
                e.printStackTrace();
                Toast.makeText(getBaseContext(),"Error To Connect",
                    Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(getBaseContext(),"Error To Connect",
                    Toast.LENGTH_SHORT).show();
            }
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
                StringBuilder sb = new StringBuilder();

                String line = null;
                while ((line = reader.readLine()) != null)
                {
                    sb.append(line + "\n");
                }
                is.close();
                page_output = sb.toString();

                Log.i("LOG", "page_output --> " + page_output); ///<--------------------------|
            /*****************remove script***********************/
            String s = page_output;
            int position = s.indexOf("<"); 

            s=s.substring(0, position - 1);

            page_output=s;
            /****************************************************/
            } catch (Exception e) {
                Log.e("Buffer Error", "Error converting result " + e.toString());
                Toast.makeText(getBaseContext(),"Buffer Error",
                    Toast.LENGTH_SHORT).show();
            }

            return page_output;
        }

            @Override
            protected void onPostExecute(String result){
                Dialog.dismiss();

                Log.i("LOG", " onPostExecute -> " + result );
                myJSON=result;
                Log.i("LOG", "myJSON" + myJSON);

                if(myJSON.trim().equals("executed")){
                    Toast.makeText(getBaseContext(),"Name Save in DB",
                        Toast.LENGTH_SHORT).show();
                    ed_name.setText("");
                }else{
                    Toast.makeText(getBaseContext(),"Error Name don't Save in DB",
                        Toast.LENGTH_SHORT).show();
            }
            }
        }
        GetDataJSON g = new GetDataJSON();
        Log.i("LOG", " GetDataJSON " );
        g.execute();
    }
}