2011-11-10 25 views
0
private void AddGroupTasks(){ 
    title1 = tTitle.getText().toString(); 
    detail1 = tDetail.getText().toString(); 
    ArrayList<NameValuePair> b = new ArrayList<NameValuePair>(); 
    Tasks = new ArrayList<String>(); 

    try{ 
     HttpClient httpclient = new DefaultHttpClient(); 
     HttpPost httppost = new HttpPost ("http://203.209.111.88/AddGroupTasks.php"); 
     httppost.setEntity(new UrlEncodedFormEntity(b)); 
     HttpResponse response = httpclient.execute(httppost); 
     HttpEntity entity = response.getEntity(); 
     is = entity.getContent(); 

     BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8); 
     StringBuilder sb = new StringBuilder(); 
     String line=null; 

     while ((line = reader.readLine()) != null) { 
      sb.append(line + "\n"); 
     } 

したがって、追加をクリックすると、情報がデータベースに追加されるはずです。しかし、それはヌル値を与えます。ちなみに、私はto-doリストアプリを書いています。データベースに情報を追加する

$Title = $_REQUEST['tTitle']; 
$Detail = $_REQUEST['tDetail']; 
$Group = $_REQUEST['spin']; 
$DueDate = $_REQUEST['tDueDate']; 

$Title = "'".$Title."'"; 
$Detail = "'".$Detail."'"; 
$Group = "'".$Group."'"; 
$DueDate = "'".$DueDate."'"; 
print $Title; 

$database = "CloudList"; 

mysql_connect("localhost","root","1234"); 

mysql_select_db($database) or die("Unable to select database"); 

$q = "INSERT INTO message(group_name,message_title,message_details,message_due) VALUES($Group,$Title,$Detail,$DueDate)"; 
$result = mysql_query($q); 
print $q; 

mysql_close(); 

これは私のPHPスクリプトです。

答えて

2

それはまだ動作しません、このコードを試してみてください、あなたのコードに置き換えて、私が起こるか知ってみましょう、

private void AddGroupTasks(){ 
title1 = tTitle.getText().toString(); 
detail1 = tDetail.getText().toString(); 
ArrayList<NameValuePair> b = new ArrayList<NameValuePair>(); 
Tasks = new ArrayList<String>(); 

try{ 
    HttpClient httpclient = new DefaultHttpClient(); 
    HttpPost httppost = new HttpPost ("http://203.209.111.88/AddGroupTasks.php"); 
    b.add(new BasicNameValuePair("tTitle", 
       "anyTitle")); 
    b.add(new BasicNameValuePair("tDetail", 
       "anyDetail")); 
    b.add(new BasicNameValuePair("spin", 
       "AnythingaboutSpin")); 
    b.add(new BasicNameValuePair("tDueDate", 
       "anytDueDate")); 
    httppost.addHeader("Content-Type", "application/x-www-form-urlencoded"); 
    httppost.setEntity(new UrlEncodedFormEntity(b, HTTP.UTF_8)); 

    HttpResponse response = httpclient.execute(httppost); 
    HttpEntity entity = response.getEntity(); 
    is = entity.getContent(); 

    BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8); 
    StringBuilder sb = new StringBuilder(); 
    String line=null; 

    while ((line = reader.readLine()) != null) { 
     sb.append(line + "\n"); 
    } 
0

[値]セクションに引用符を設定してください。

$q = "INSERT INTO message(group_name,message_title,message_details,message_due) VALUES('$Group','$Title','$Detail','$DueDate')"; 
+0

:それは次のようになります。私はテストにトーストを使用し、それは何も得られません。 –

関連する問題