POST查询的奇怪行为

时间:2012-05-31 12:03:02

标签: android post

项目 id_category 未发送到服务器,但其他项目发送没有问题。

add.php:

<?php
header("Content-Type: text/html;charset=utf-8");
require_once('../php/mysql_conect.php');
$use_db=mysql_query("use open_service;");

$date=date("Y-m-d");
$time=date("H:i:s");

$insert=mysql_query("insert into records(id_category,name,phone,device_id,address,text,publish_date,publish_time) value('$_POST[id_categoty]','$_POST[name]','$_POST[phone]','$_POST[device_id]','$_POST[address]','$_POST[text]','$date','$time');");
?>

我的部分代码:

  

//获取id设备

       *TelephonyManager telMgr=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
       String device_id = telMgr.getDeviceId().toString();


       name_post = name.getText().toString();
       phone_post=phone.getText().toString();
       address_post=address.getText().toString();
       comment_post=comment.getText().toString();
       String id_category="1";

    // Create a new HttpClient and Post Header
                    HttpClient httpclient = new DefaultHttpClient();
                    httpclient.getParams().setParameter("http.protocol.version",
     

HttpVersion.HTTP_1_1);                           httpclient.getParams()。setParameter(“http.socket.timeout”,new   整数(2000));                           httpclient.getParams()。的setParameter( “http.protocol.content-字符集”,   “UTF-8”);                           HttpPost httppost = new HttpPost(“http://10.100.100.20/test/mobile/add.php”);

                    try {
                            // Add your data
                            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6);
                            nameValuePairs.add(new BasicNameValuePair("name", name_post));
                            nameValuePairs.add(new BasicNameValuePair("phone", phone_post));
                            nameValuePairs.add(new BasicNameValuePair("address", address_post));
                            nameValuePairs.add(new BasicNameValuePair("text", comment_post));
                            nameValuePairs.add(new BasicNameValuePair("device_id", device_id));
                            nameValuePairs.add(new BasicNameValuePair("id_category", id_category));<--It's don send to
     

服务器                                   httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,“UTF-8”));

                            response = httpclient.execute(httppost);
               //Создаем уведомление
            Toast toast=Toast.makeText(getBaseContext(), "Заявка успешно отправлена", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, -200);
            toast.show();

            //Возвращаемся а предыдущие Activity
             Intent intent= new Intent();
             intent.setClass(getApplicationContext(), EservisActivity.class);
             startActivity(intent);

                    }*

1 个答案:

答案 0 :(得分:0)

add.php中有一个拼写错误:$_POST[id_categoty]而不是$_POST[id_category]