代码如下
安卓端
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
newThread(){
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
newThread(){
@Override
publicvoidrun()
{
ArrayListparams=newArrayList();
params.add(newBasicNameValuePair(“name”,”SUCCESS”));
params.add(newBasicNameValuePair(“age”,”666666″));
try{
HttpClienthttpclient=newDefaultHttpClient();
HttpPosthttppost=newHttpPost(“http://192.168.210.51/login.php”);
httppost.setEntity(newUrlEncodedFormEntity(params));
httpclient.execute(httppost);
}catch(Exceptione){
Log.i(“eeeeee”,“eeeeeeerrrrrrrrrr”);
}
}
}.start();
}
}
php端
echo“HelloWorld!”;
$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
”;
die(print_r(sqlsrv_errors(),true));
}
else{echo“success”;}
$sql=”INSERTINTOTest(name,age)VALUES(“$_POST[name]”,”$_POST[age]”)”;
$query=sqlsrv_query($con,$sql);
?>
解决方案
20
可以打trace么
20
用volley试一试
如果觉得《php取不到post数据库 安卓post 数据到php 在写入数据库老是不成功 数据post不到php...》对你有帮助,请点赞、收藏,并留下你的观点哦!