Android的VMD的MySQL插件和显示对话框 [英] Android VMD MySQL insert and showing dialog

查看:193
本文介绍了Android的VMD的MySQL插件和显示对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个Android应用程序做一个简单的插入。我可以从浏览器通过连接?进入=从浏览器的采样值运行我的 PHP 脚本,但是当我运行Android的应用程序,我没有得到任何插件。

I am trying to do a simple insert from an Android application. I can run my php script from the browser by concatenating ?entry="Sample value from browser", but when I run the application from Android, I get no insert.

这里是我打电话使用JSON和执行的AsyncTask插入类:

Here is where I am calling the insert class that uses JSON and implements AsyncTask:

package us.jtaylorok.android.sqlite.first;

import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

public class RemoteInsert extends AsyncTask<Void, String,String >{

    protected String TAG;
    protected Context context;
    protected String input;
    protected ProgressDialog progressDialog;

    public RemoteInsert(String i,Context c){
        this.input = i;
        this.context = c;
    }


    protected void onPreExecute() {
        //ProgressDialog progressDialog; // = new ProgressDialog(context);

        //progressDialog=ProgressDialog.show(,"Please Wait..","Sending data to database", false);
        progressDialog=ProgressDialog.show(context,"Please Wait..","Sending data to database", false);
    }

    @Override
    protected String doInBackground(Void... params) {
        try {
            HttpClient httpclient = new DefaultHttpClient();
            //HttpPost httppost = new HttpPost("http://localhost/index.php");
            //HttpPost httppost = new HttpPost("http://10.253.8.88/patient_data/patient_data.php");
            HttpPost httppost = new HttpPost("http://10.100.205.72/patient_data/patient_data.php");

            ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
            postParameters.add(new BasicNameValuePair("entry", "Input from Android"));

            httppost.setEntity(new UrlEncodedFormEntity(postParameters));                   
            HttpResponse response = httpclient.execute(httppost);
            Log.i("postData", response.getStatusLine().toString());
        } catch(Exception e) {
            Log.e(TAG, "Error:  "+e.toString());
        }  

        return "";
    }

    protected void onPostExecute(String result) {
        progressDialog.dismiss(); 
        Toast.makeText(context, "Finished", Toast.LENGTH_LONG).show(); 
    }
}

这是我的PHP脚本:

And here is my PHP script:

<?php
    // mysql_connect("host","username","password");
    mysql_connect("localhost","user1","mypassword");
    mysql_select_db("test");

    $entry_value = $_REQUEST["entry"];
    $query = "INSERT INTO patientdata (entry) values (".$entry_value.");";
    if( !mysql_query($query) ) { 
        /*insert failed*/ 
    }

    mysql_close();
?>

同样,这个完美的作品,如果我把它从浏览器,但在实施之前抛出一个异常的AsyncTask

我得到的AVD以显示添加和删除,但是当我这样做,没有在我的的Apache2 的access_log 或不要求 error_log中。有什么建议?

I do get the AVD to display the add and remove, but when I do that there is no request in my apache2 access_log or error_log. Any suggestions?

推荐答案

这是不是为这个特殊问题的问题。这个问题是一个神奇的报价在php.ini设定

That was not the issue for this particular problem. The issue was a magic quotes setting in the php.ini

这篇关于Android的VMD的MySQL插件和显示对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆