您的位置:首页 > 编程语言 > PHP开发

安卓post 数据到php 在写入数据库老是不成功, 数据post不到php

2017-03-25 20:03 232 查看
代码如下

安卓端

public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        new Thread(){

@Override

  public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        new Thread(){

            @Override

            public void run()

            {

ArrayList params = new ArrayList();

                params.add(new BasicNameValuePair("name","SUCCESS"));

                params.add(new BasicNameValuePair("age","666666"));

try {

                    HttpClient httpclient = new DefaultHttpClient();

                    HttpPost httppost = new HttpPost("http://192.168.210.51/login.php");

                    httppost.setEntity(new UrlEncodedFormEntity(params));

                    httpclient.execute(httppost);

                } catch (Exception e) {

                    Log.i("eeeeee", "eeeeeeerrrrrrrrrr");

                }

}

        }.start();

    }

       }

php端

<?php

echo "Hello World!";

$serverName = "192.168.208.42";  

$uid = "sa";  

$pwd = "sadell";  

$database = "my_db";

$connectionInfo = array("PWD"=>$pwd,"UID"=>$uid,"Database"=>$database);  

$con = sqlsrv_connect($serverName,$connectionInfo); 

if (!$con)

{

echo "FAIL<br/>";

    die(print_r( sqlsrv_errors(),true));

}

else{echo "success";}

$sql="INSERT INTO Test(name, age)VALUES ('$_POST[name]','$_POST[age]')";

$query=sqlsrv_query($con,$sql);

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: