Code Bye

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

代码如下
安卓端
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);
?>
解决方案

20

可以打trace么

20

用volley试一试

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明安卓post 数据到php 在写入数据库老是不成功, 数据post不到php