Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将数据添加到本地主机上的Mysql数据库_Php_Android_Mysql_Localhost_Wampserver - Fatal编程技术网

Php 将数据添加到本地主机上的Mysql数据库

Php 将数据添加到本地主机上的Mysql数据库,php,android,mysql,localhost,wampserver,Php,Android,Mysql,Localhost,Wampserver,我正在尝试创建注册表,但应用程序一直崩溃 我想这可能是我的虚拟仿真器的URL,我尝试了10.0.2.2和10.0.3.2,我选中了虚拟框以查看要使用的地址,我得到了192.168.79.2,但它们都不起作用 这是我的BackgroundTask.java类 这是我的register.php文件 你的解决方案 从我所看到的,第一行应该是urlcoder.encodeuser,UTF-8吗?显然,您的PHP表单显示$names=$\u POST[names];,这意味着POST变量应该是names

我正在尝试创建注册表,但应用程序一直崩溃 我想这可能是我的虚拟仿真器的URL,我尝试了10.0.2.2和10.0.3.2,我选中了虚拟框以查看要使用的地址,我得到了192.168.79.2,但它们都不起作用

这是我的BackgroundTask.java类

这是我的register.php文件

你的解决方案 从我所看到的,第一行应该是urlcoder.encodeuser,UTF-8吗?显然,您的PHP表单显示$names=$\u POST[names];,这意味着POST变量应该是names

如果数据库未配置空变量,则会出错

String data = URLEncoder.encode("user", "UTF-8")+"="+URLEncoder.encode(names, "UTF-8")+"&"+
              URLEncoder.encode("user_name", "UTF-8")+"="+URLEncoder.encode(user_name, "UTF-8")+"&"+
              URLEncoder.encode("user_pass", "UTF-8")+"="+URLEncoder.encode(user_pass, "UTF-8");
将异步任务调用为

ArrayList<String> params = new ArrayList<String>();
                        params.add(name);
                        params.add(userId);
                        params.add(passw);
                        new registerTask().execute(params);
试试这个:

 public class registerTask extends AsyncTask<ArrayList<String>, Void, ArrayList<String>> {

            @Override
            protected void onPreExecute() {
                progress1.setVisibility(View.VISIBLE);
            }

            protected ArrayList<String> doInBackground(ArrayList<String>... passing) {
                ArrayList<String> result = new ArrayList<String>();
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://192.168.79.2/webapp/register.php");
                String responses = null;
                ArrayList<String> data = passing[0];
                String name = data.get(0);
                String uid = data.get(1);
                String passw = data.get(2);
                int ik;
                try {
                    //add data
                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
                    nameValuePairs.add(new BasicNameValuePair("names", name));
                    nameValuePairs.add(new BasicNameValuePair("user_name", uid));
                    nameValuePairs.add(new BasicNameValuePair("user_pass", passw));
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                    //execute http post
                    HttpResponse response = httpclient.execute(httppost);
//You will get the response from server in response
                    HttpEntity entity = response.getEntity();
                    String content = EntityUtils.toString(entity);
                } catch (ClientProtocolException e) {
                } catch (IOException e) {
                }
                return "Success"; //return result
            }

            protected void onPostExecute(ArrayList<String> result) {
            }
        }
我不知道我是否错过了什么。。。。
试试这个。

谢谢@lefsFlare我的导入有问题

我改为:javax.net.ssl.HttpsURLConnection;
收件人:java.net.HttpURLConnection

你的港口是什么?例如,我有57714是我的端口,在你的模拟器中检查应用程序。我如何找到这个端口?以前从未试过!试试这个:让我知道它对你有用吗?10.0.3.2成功了我的导入中有一个问题。谢谢你,我修复了它,但它还是崩溃了。我运行了调试器,它在这一行httpsURLConnection.setRequestMethodPOST崩溃了@OdeyM.Khalaf调试器怎么说?@OdeyM.Khalaf这很奇怪,你能把堆栈跟踪粘贴到帖子的末尾吗?我想这是错的,我给了你错误的消息:由以下原因引起:java.lang.ClassCastException:com.android.okhttp.internal.huc.HttpURLConnectionImpl不能转换为javax.net.ssl.HttpsURLConnectionOk,你能贴上进口商品吗?我想你可能进口错了包装,但我不确定。
ArrayList<String> params = new ArrayList<String>();
                        params.add(name);
                        params.add(userId);
                        params.add(passw);
                        new registerTask().execute(params);
 public class registerTask extends AsyncTask<ArrayList<String>, Void, ArrayList<String>> {

            @Override
            protected void onPreExecute() {
                progress1.setVisibility(View.VISIBLE);
            }

            protected ArrayList<String> doInBackground(ArrayList<String>... passing) {
                ArrayList<String> result = new ArrayList<String>();
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://192.168.79.2/webapp/register.php");
                String responses = null;
                ArrayList<String> data = passing[0];
                String name = data.get(0);
                String uid = data.get(1);
                String passw = data.get(2);
                int ik;
                try {
                    //add data
                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
                    nameValuePairs.add(new BasicNameValuePair("names", name));
                    nameValuePairs.add(new BasicNameValuePair("user_name", uid));
                    nameValuePairs.add(new BasicNameValuePair("user_pass", passw));
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                    //execute http post
                    HttpResponse response = httpclient.execute(httppost);
//You will get the response from server in response
                    HttpEntity entity = response.getEntity();
                    String content = EntityUtils.toString(entity);
                } catch (ClientProtocolException e) {
                } catch (IOException e) {
                }
                return "Success"; //return result
            }

            protected void onPostExecute(ArrayList<String> result) {
            }
        }