duankuai6586 2016-06-10 14:54
浏览 42

当使用mysql和php连接android应用程序时,会出现未定义的索引。 一定是什么原因?

Here is the php script I'm using for registration of new users

PHP

<?php
require "init.php";

$name      = $_POST["user"];
$user_name = $_POST["user_name"];
$user_pass = $_POST["user_pass"];

$sql_query = "insert into user_info values('$name','$user_name','$user_pass');";


?>

Android Log

06-10 19:55:40.395 4694-4838/com.example.clint.mysqltesting W/System.err: java.io.FileNotFoundException: http://192.168.0.103/webapp/register.php

My Background Task BackgroundTask.java

package com.example.clint.mysqltesting;

import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

/**
* Created by CLINT on 6/11/2016.
*/
public class BackgroundTask extends AsyncTask<String, Void, String> {

    Context ctx;

    BackgroundTask(Context ctx){

        this.ctx = ctx;


    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected String doInBackground(String... params) {

        String reg_url = "http://192.168.0.103/webapp/register.php";
        String login_url = "http://192.168.0.103/webapp/login.php";
        String method = params[0];
        if(method.equals("register")){

            String name = params[1];
            String user_name = params[2];
            String user_pass = params[3];

            try {
                URL url = new URL(reg_url);
                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                httpURLConnection.setRequestMethod("POST");
                httpURLConnection.setDoOutput(true);
                OutputStream OS = httpURLConnection.getOutputStream();
                BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(OS, "UTF-8"));
                String data = URLEncoder.encode("user", "UTF-8")+ "=" +URLEncoder.encode(name, "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");
                bufferedWriter.write(data);
                bufferedWriter.flush();
                bufferedWriter.close();
                OS.close();
                InputStream IS = httpURLConnection.getInputStream();
                IS.close();
                return "registration Success";


            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

        return null;
    }

    @Override
    protected void onProgressUpdate(Void... values) {
        super.onProgressUpdate(values);
    }

    @Override
    protected void onPostExecute(String result) {
        Toast.makeText(ctx, result, Toast.LENGTH_LONG).show();
    }

}

What is the reason that I am getting an Undefined Index? I have seen some questions related to this that are saying use the (isset) can resolve this trouble. I have tried doing this, but still not able to add the data to the database from the Android app.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line