Java 将数据从android注册到phpmyadmin时出错

Java 将数据从android注册到phpmyadmin时出错,java,php,android,Java,Php,Android,我是Android Studio的新手,我正在寻找这段代码的解决方案,在我将Android中输入的数据输入phpmyadmin中的db之前,但是现在我不知道错误在哪里,我所做的唯一一件事是在php文件中添加更多的字段。到目前为止,我掌握的情况如下: Main2Activity.java package com.example.myapplication; import android.annotation.SuppressLint; import android.app.DatePickerD

我是Android Studio的新手,我正在寻找这段代码的解决方案,在我将Android中输入的数据输入phpmyadmin中的db之前,但是现在我不知道错误在哪里,我所做的唯一一件事是在php文件中添加更多的字段。到目前为止,我掌握的情况如下:

Main2Activity.java

package com.example.myapplication;

import android.annotation.SuppressLint;
import android.app.DatePickerDialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
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.JsonObjectRequest;
import com.android.volley.toolbox.JsonRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONObject;
import java.util.Calendar;
import java.util.Objects;


public class Main2Activity extends AppCompatActivity implements View.OnClickListener, Response.Listener<JSONObject>, Response.ErrorListener   {

    private static final String TAG = "Main2Activity";
    private EditText nd, date, dbruto, veintiuno, subt1, descuento5, subt2,  descuento10, descuento15, subt3, descuento2, subt4,  descuento1, tdescuento, dtotal;
    private RequestQueue rq;
    private JsonRequest jrq;
    private Button rdiezmo;

    private DatePickerDialog.OnDateSetListener nDateSetListener;

    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        rq = Volley.newRequestQueue(this);
        rdiezmo = findViewById(R.id.btnrd);
        date=findViewById(R.id.txtdate);
        date.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view) {
                Calendar calendar=Calendar.getInstance();
                int year=calendar.get(Calendar.YEAR);
                int month=calendar.get(Calendar.MONTH);
                int day=calendar.get (Calendar.DAY_OF_MONTH);

                DatePickerDialog dialog = new DatePickerDialog(Main2Activity.this,
                        android.R.style.Theme_Holo_Light_Dialog_MinWidth,
                        nDateSetListener,
                        year,month,day);
                Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                dialog.show();
            }
        });
        nDateSetListener = new
                DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker datePicker, int year, int month, int day) {
                        month = month +1;
                        Log.d(TAG,"onDateSet: mm/dd/yyy: "+ year +"-"+month+"-"+day);
                        String ndate = year + "-"+month+"-"+day;
                        date.setText(ndate);
                    }
                };

        TextView txtBienvenido = findViewById(R.id.txtbienvenido);
        txtBienvenido.setText("¡Por favor! Ingrese los datos");
        nd = findViewById(R.id.txtndom);
        dbruto = findViewById(R.id.txtdbruto);
        String dato = getIntent().getStringExtra("dato");
        dbruto.setText(dato);
        veintiuno = findViewById(R.id.txtd21);
        subt1 = findViewById(R.id.txts1);
        descuento5 = findViewById(R.id.desc5);
        subt2 = findViewById(R.id.txts2);
        descuento10 = findViewById(R.id.desc10);
        descuento15 = findViewById(R.id.desc15);
        subt3 = findViewById(R.id.txts3);
        descuento2 = findViewById(R.id.desc2);
        subt4 = findViewById(R.id.txts4);
        descuento1 = findViewById(R.id.desc1);
        tdescuento = findViewById(R.id.txtdesc);
        dtotal = findViewById(R.id.txtdiezmob);
        findViewById(R.id.btncd).setOnClickListener(this);
        findViewById(R.id.btnrd).setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btncd:
                //Calcula descuento 21%
                float v21 = Float.parseFloat((dbruto.getText().toString()));
                float d21 = (v21 * 21) / 100;
                String r1 = String.valueOf((double) d21);
                veintiuno.setText((r1));

                //Calcula subtotal 1
                float s1 = v21 - d21;
                String r2 = String.valueOf((double) s1);
                subt1.setText((r2));

                //Calcula descuento 5%
                float d5 = (s1 * 5) / 100;
                String r3 = String.valueOf((double) d5);
                descuento5.setText((r3));

                //Calcula subtotal 2
                float s2 = s1 - d5;
                String r4 = String.valueOf((double) s2);
                subt2.setText((r4));

                //Como se está calculando el 5% este valor es 0
                float d10 = 0;
                String r5 = String.valueOf((double) d10);
                descuento10.setText((r5));

                //Como se está calculando el 5% este valor es 0
                float d15 = 0;
                String r6 = String.valueOf((double) d15);
                descuento15.setText((r6));

                //Como se está calculando el 5% este valor es 0
                float s3 = 0;
                String r7 = String.valueOf((double) s3);
                subt3.setText((r7));

                //Calcula descuento 2%
                float d2 = (s2 * 2) / 100;
                String r8 = String.valueOf((double) d2);
                descuento2.setText((r8));

                //Calcula subtotal 4
                float s4 = s2 - d2;
                String r9 = String.valueOf((double) s4);
                subt4.setText((r9));


                //Calcula descuento 1%
                float d1 = (s4 * 1) / 100;
                String r10 = String.valueOf((double) d1);
                descuento1.setText((r10));

                //Calcula total descuento
                float tdesc = d21 + d5 + d2 + d1;
                String r11 = String.valueOf((double) tdesc);
                tdescuento.setText((r11));

                //Calcula diezmo neto
                float dneto = s4 - d1;
                String r12 = String.valueOf((double) dneto);
                dtotal.setText((r12));

                break;

            case R.id.btnrd:

                String url =
                        "https://ipucsegundaalgarrobo.000webhostapp.com/diezmo15.php?nd=" + nd.getText().toString() + "&fd=" + date.getText().toString() +
                                "&db=" + dbruto.getText().toString() + "&sb1=" + dbruto.getText().toString() + "&d1=" + veintiuno.getText().toString() +
                                "&sb2=" + subt1.getText().toString() + "&d2=" + descuento5.getText().toString() + "&sb3=" + subt2.getText().toString() +
                                "&d3=" + descuento10.getText().toString() + "&d4=" + descuento15.getText().toString() + "&sb4=" + subt3.getText().toString() +
                                "&d5=" + descuento2.getText().toString() + "&sb5=" + subt4.getText().toString() + "&d6=" + descuento1.getText().toString() +
                                "&td=" + tdescuento.getText().toString() + "&dn=" + dtotal.getText().toString();

                jrq = new JsonObjectRequest(Request.Method.GET, url, null, this, this);
                rq.add(jrq);
                Log.i(" URL ", " Url de petición " +url);
                break;
        }
    }
    @Override
    public void onErrorResponse(VolleyError error) {
        Toast.makeText(this, "No se pudo registrar los datos" + error.toString(),Toast.LENGTH_LONG).show();
    }
    @Override
    public void onResponse(JSONObject response) {
        Toast.makeText(this, "Se ha registrado los datos correctamente",Toast.LENGTH_SHORT).show();
        limpiarRegistros();
    }
    private void limpiarRegistros() {
        nd.setText("");
        date.setText("");
        dbruto.setText("");
        veintiuno.setText("");
        subt1.setText("");
        descuento5.setText("");
        subt2.setText("");
        descuento10.setText("");
        descuento15.setText("");
        descuento2.setText("");
        subt3.setText("");
        subt4.setText("");
        descuento1.setText("");
        tdescuento.setText("");
        dtotal.setText("");
    }
}
package com.example.myapplication;
导入android.annotation.SuppressLint;
导入android.app.DatePickerDialog;
导入android.graphics.Color;
导入android.graphics.drawable.ColorDrawable;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.view;
导入android.widget.Button;
导入android.widget.DatePicker;
导入android.widget.EditText;
导入android.widget.TextView;
导入android.widget.Toast;
导入com.android.volley.Request;
导入com.android.volley.RequestQueue;
导入com.android.volley.Response;
导入com.android.volley.VolleyError;
导入com.android.volley.toolbox.JsonObjectRequest;
导入com.android.volley.toolbox.JsonRequest;
导入com.android.volley.toolbox.volley;
导入org.json.JSONObject;
导入java.util.Calendar;
导入java.util.Objects;
公共类Main2Activity扩展AppCompatActivity实现View.OnClickListener、Response.Listener、Response.ErrorListener{
私有静态最终字符串TAG=“Main2Activity”;
私人编辑文本nd、日期、dbruto、Ventiuno、subt1、descuento5、subt2、descuento10、descuento15、subt3、descuento2、subt4、descuento1、tdescuento、dtotal;
专用请求队列rq;
私有JSONRequestJRQ;
专用按钮rdiezmo;
私有DatePickerDialog.OnDateSetListener和DateSetListener;
@SuppressLint(“SetTextI18n”)
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
rq=Volley.newRequestQueue(this);
rdiezmo=findviewbyd(R.id.btnrd);
日期=findViewById(R.id.txtdate);
date.setOnClickListener(新视图.OnClickListener()
{
@凌驾
公共void onClick(视图){
日历=Calendar.getInstance();
int year=calendar.get(calendar.year);
int month=calendar.get(calendar.month);
int day=calendar.get(calendar.day/u月);
DatePickerDialog对话框=新建DatePickerDialog(Main2Activity.this,
android.R.style.Theme\u Holo\u Light\u Dialog\u MinWidth,
数据列表器,
年、月、日);
Objects.requirennoull(dialog.getWindow()).setBackgroundDrawable(新的ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
});
nDataSetListener=新建
DatePickerDialog.OnDateSetListener(){
@凌驾
公共无效onDateSet(日期选择器日期选择器,整数年,整数月,整数天){
月=月+1;
日志d(标签“onDateSet:mm/dd/yyy:“+年+”-“+月+”-“+日”);
字符串日期=年+“-”+月+“-”+日;
日期:setText(数据);
}
};
TextView txtBienvenido=findViewById(R.id.txtBienvenido);
txtBienvenido.setText(“赞成!赞成!”;
nd=findViewById(R.id.txtndom);
dbruto=findViewById(R.id.txtdbruto);
字符串dato=getIntent().getStringExtra(“dato”);
dbruto.setText(dato);
Ventiuno=findViewById(R.id.txtd21);
subt1=findViewById(R.id.txts1);
descuento5=findViewById(R.id.descuento5);
subt2=findViewById(R.id.txts2);
descuento10=findViewById(R.id.descuento10);
descuento15=findViewById(R.id.descuento15);
subt3=findViewById(R.id.txts3);
DescentO2=findViewById(R.id.Descent2);
subt4=findViewById(R.id.txts4);
descuento1=findViewById(R.id.desc1);
tdescunto=findviewbyd(R.id.txtdesc);
dtotal=findViewById(R.id.txtdiezmob);
findviewbyd(R.id.btncd).setOnClickListener(this);
findviewbyd(R.id.btnrd).setOnClickListener(this);
}
@凌驾
公共void onClick(视图v){
开关(v.getId()){
案例R.id.btncd:
//下尿路结石21%
float v21=float.parseFloat((dbruto.getText().toString());
浮点数d21=(v21*21)/100;
字符串r1=String.valueOf((双精度)d21);
Ventiuno.setText((r1));
//结石小计1
浮点数s1=v21-d21;
字符串r2=String.valueOf((双)s1);
subt1.setText((r2));
//降钙结石5%
浮点数d5=(s1*5)/100;
String r3=String.valueOf((双精度)d5);
descuento5.setText((r3));
//结石小计2
浮点数s2=s1-d5;
字符串r4=String.valueOf((双精度)s2);
subt2.setText((r4));
//科莫-埃斯塔卡兰多5%埃斯特瓦勒0
浮动d10=0;
字符串r5=String.valueOf((双精度)d10);
descunto10.setText((r5));
//科莫-埃斯塔卡兰多5%埃斯特瓦勒0
浮动d15=0;
字符串r6=字符串.valueOf((双精度)d15);
descuento15.setText((r6));
//科莫-埃斯塔卡兰多5%埃斯特瓦勒0
浮点数s3=0;
String r7=String.valueOf((双精度)s3);
第三款:设置文本((r7));
//降钙剂2%
浮点数d2=(s2*2)/100;
字符串r8=字符串.valueOf((双精度)d2);
descento2.setText((r8));
<?php

$json=array();
    if(isset($_GET["nd"]) && ($_GET["fd"]) &&($_GET["db"]) && ($_GET["sb1"]) && ($_GET["d1"]) && ($_GET["sb2"]) && ($_GET["d2"]) && ($_GET["sb3"]) && ($_GET["d3"]) && ($_GET["d4"]) && ($_GET["sb4"]) && ($_GET["d5"]) && ($_GET["sb5"]) && ($_GET["d6"]) && ($_GET["td"]) && isset($_GET["dn"])){
        $nd = $_GET['nd'];
        $fd = $_GET['fd'];
        $db = $_GET['db'];
        $sb1 = $_GET['sb1'];
        $d1 = $_GET['d1'];
        $sb2 = $_GET['sb2'];
        $d2 = $_GET['d2'];
        $sb3 = $_GET['sb3'];
        $d3 = $_GET['d3'];
        $d4 = $_GET['d4'];
        $sb4 = $_GET['sb4'];
        $d5 = $_GET['d5'];
        $sb5 = $_GET['sb5'];
        $d6 = $_GET['d6'];
        $td = $_GET['td'];
        $dn = $_GET['dn'];

$conexion = mysqli_connect 
("localhost","tubd","tucontrasena","tutabla" ) or die  
("Sin Conexion");

        $consulta="INSERT INTO diezmos15(ndom, fdom, dbru, subt1,  
desc21, subt2, desc5, subt3, desc10, desc15, subt4, desc2, subt5, desc1, tdesc, dneto) 

VALUES  
('{$nd}','{$fd}','{$db}','{$sb1}','{$d1}','{$sb2}','{$d2}','{$sb3}','{$d3}','{$d4}','{$sb4}','{$d5}','{$sb5}','{$d6}','{$td}','{$dn}')";
        $resultado=mysqli_query($conexion,$consulta);
        if($consulta){
           $consulta="SELECT * FROM diezmos  WHERE 

ndom='{$nd}'";
           $resultado=mysqli_query($conexion,$consulta);

            if($reg=mysqli_fetch_array($resultado)){
                $json['datos'][]=$reg;
            }
            mysqli_close($conexion);
            echo json_encode($json);
        }
        else{
            $results['nd']='';
            $results['fd']='';
            $results['db']='';
            $results['sb1']='';
            $results['d1']='';
            $results['sb2']='';
            $results['d2']='';
            $results['sb3']='';
            $results['d3']='';
            $results['d4']='';
            $results['sb4']='';         
            $results['d5']='';
            $results['sb5']='';
            $results['d6']='';
            $results['td']='';
            $results['dn']='';
            $json['datos'][]=$results;
            echo json_encode($json);
        }
    }
    else{   
            $results['nd']='';
            $results['fd']='';
            $results['db']='';
            $results['sb1']='';
            $results['d1']='';
            $results['sb2']='';
            $results['d2']='';
            $results['sb3']='';
            $results['d3']='';
            $results['d4']='';
            $results['sb4']='';         
            $results['d5']='';
            $results['sb5']='';
            $results['d6']='';
            $results['td']='';
            $results['dn']='';
            $json['datos'][]=$results;
            echo json_encode($json);
        }
?>