【问题标题】:Code not sending data over Volley to mysql代码不通过 Volley 向 mysql 发送数据
【发布时间】:2016-08-11 09:18:51
【问题描述】:

我正在尝试使用 volley post 方法更新 mysql 数据库,即使 php 被成功调用但数据库没有收到发送的值。我的 php 使用发送的值和由 php 生成的唯一 id 更新表,php 成功触发查询并更新 id 列,但不更新从 android 发送的数据列。

下面是java代码

package com.attosectechnolabs.cardviewone;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import java.util.HashMap;
import java.util.Map;

public class forum extends AppCompatActivity {

    String thread_text, User = "Test";
    Context ctx;
    EditText new_thread_text;
    TextView resulttemp;
    Button submit_thread, cancel_thread;
    private static final String REGISTER_URL = "http://attosectechnolabs.com/Projects/eduapp/thread.php";
    public static final String KEY_THREAD = "thread";
    public static final String KEY_USERNAME = "User";

    public forum() {
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        setContentView(R.layout.forum);

        submit_thread = (Button) findViewById(R.id.submit_thread);
        cancel_thread = (Button) findViewById(R.id.cancel_thread);
        new_thread_text = (EditText) findViewById(R.id.new_thread_text);
        resulttemp = (TextView) findViewById(R.id.resulttemp);

        submit_thread.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                insertThreadText();

            }
        });
    }

    private void insertThreadText() {

        final String thread_text = new_thread_text.getText().toString().trim();
        resulttemp.setText(thread_text);

        StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        Toast.makeText(forum.this, response, Toast.LENGTH_LONG).show();
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(forum.this, error.toString(), Toast.LENGTH_LONG).show();
                    }
                }) {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();
                params.put(KEY_THREAD, thread_text);
                params.put(KEY_USERNAME, User);
                return params;
            }

        };
        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);
    }
}

似乎我弄乱了发布请求,但我不知道它是什么。

【问题讨论】:

  • Volley 无法向 mysql 发送数据。
  • 请发布您的回复或错误日志..

标签: java php android mysql android-volley


【解决方案1】:

对不起,这是一个愚蠢的错误, 而不是

public static final String KEY_THREAD = "thread";

应该是的

public static final String KEY_THREAD = "thread_text";

感谢您的宝贵时间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-25
    • 2019-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多