0

When I try to send data from android to php, I get these yellow warnings on logcat:

Invalid use of SingleClientConnManager: connection still allocated

and:

W/SingleClientConnManager(274): Make sure to release the connection before allocating another one.

My codes like this:

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("email", "")); 
    InputStream is=null;
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://zzzzz.com/zzz.php");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        httpclient.execute(httppost);
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is=entity.getContent();

    } catch (IOException e) {
    }

And in my zzz.php I have:

<?php

 $email = "aaa";

 if (session_id() == "")
 {
  session_start();
 }
 if (!isset($_SESSION['username']))
 {
   header('Location: ./index.php');
   exit;
 }
 else
 {

 $username = "******";
 $password = "****";
 $host = "****";
 $database = "****";

 $db = mysql_connect($host, $username, $password);
 if (!$db)
  {
  die('Failed to connect to database server!<br>'.mysql_error());
  }
 else
  {
   mysql_select_db($database, $db) or die('Failed to select database<br>'.mysql_error()); 
   mysql_query("UPDATE Users SET lat='".$email."' WHERE username='{$_SESSION['username']}'");
  }
}
?>

By the way, I know mysql_query deprecated, I'll change it. Anyway above codes does not work. I mean it doesn't write "aaa" on lat value in mysql. Where is wrong ?

4

2 回答 2

0

在我看来, $_SESSION['username'] 任何时候都没有设置。

于 2012-11-30T11:55:47.263 回答
0

你需要这两行吗?

 httpclient.execute(httppost);
 HttpResponse response = httpclient.execute(httppost);
于 2012-11-30T12:39:43.443 回答