duandai0373 2011-11-11 22:33
浏览 42

试图将数据发布到php但数据未正确读取

Here is the code for the php server:

?php


    //from the online tutorial:

    $usr = "bikemap";
      $pwd = "pedalhard";
      $db = "test";
      $host = "localhost";

      $cid = mysql_connect($host,$usr,$pwd);

      if (!$cid) { echo("ERROR: " . mysql_error() . "
"); }

      $userID = $_POST['userID'];
      $date = $_POST['date'];
      $time = $_POST['time'];

      $lat = $_POST['lat'];
      $long = $_POST['longi'];
      $alt = $_POST['alt'];
       mysql_select_db("test");
      mysql_query("INSERT INTO gpsdata (userID, date, time, lat, longi, alt) VALUES ('$userID', '$date', '$time', '$lat','$longi','$alt') ") or die(mysql_error()); 

      /*$SQL = " INSERT INTO gpsdata ";
    $SQL = $SQL . " (userID, date, time, lat, longi, alt) VALUES ";
    $SQL = $SQL . " ('$userID', '$date', '$time', '$lat','$longi','$alt') ";
    $result = mysql_query("$SQL");

    if (!$result) {
        echo("ERROR: " . mysql_error() . "
$SQL
"); } */

    //echo ("New Link Added
");



    mysql_close($cid); 
    ?>

Data sent from my android app:

 [userID=Loren, date=today, time=now, lat=bit 1, longi=bit 2, alt=bit 3]

For some reason my php doesnt read the data sent from the android app (shown above) properly but if I send the same data from a local web page the data posted parses as it should.

public static void sendAccelerationData(String userIDArg, String dateArg, String timeArg,
            String timeStamp, String lat, String longi, String alt)
    {


        //Add data to be send.
        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6);
        nameValuePairs.add(new BasicNameValuePair("userID", userIDArg));
        nameValuePairs.add(new BasicNameValuePair("date",dateArg));
        nameValuePairs.add(new BasicNameValuePair("time",timeArg));
        //nameValuePairs.add(new BasicNameValuePair("timeStamp",timeStamp));

        nameValuePairs.add(new BasicNameValuePair("lat",lat));
        nameValuePairs.add(new BasicNameValuePair("longi",longi));
        nameValuePairs.add(new BasicNameValuePair("alt",alt));

        //this.sendData(nameValuePairs);
        try
        {
            TextLog.addLogStuff("SERV Trying to connect to Server");
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new      
            HttpPost("http://myserver.php");
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            Log.i("ServerConn", response.getStatusLine().toString());
            TextLog.addLogStuff("SERV PostData:  "  +response.getStatusLine().toString());
                //Could do something better with response.
        }
        catch(Exception e)
        {
            Log.e("log_tag", "Error:  "+e.toString());
            TextLog.addLogStuff("SERV Connection error:  " +e.toString());
        }  
    }
  • 写回答

3条回答 默认 最新

  • douwen5985 2011-11-11 23:26
    关注

    I'd need to see the code you are using in Android to POST the data to know for sure, but it seems like your Android app isn't posting the data in the correct format. You should be doing it something like this: Android, Java: HTTP POST Request.

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效