Jump to content

Recommended Posts

Hi again

 

Another issue.

This is my php code

if ($tag == 'reqSalasCheck') {
        $sala = filter_input(INPUT_POST, 'sala');
        $inicio = filter_input(INPUT_POST, 'inicio');
        $fim = filter_input(INPUT_POST, 'fim');
        $data = filter_input(INPUT_POST, 'dataFinal');
        $dias = strftime('%A', strtotime($data));
        $newDate = date("Y-m-d", strtotime($data));
        $diaId = mysql_query("SELECT * FROM `ebspma_paad_ebspma`.`semana_dias` WHERE dia ='$dias'");
        $diaRow = mysql_fetch_row($diaId)or die(mysql_error());
        $Dias = $diaRow[0];
        if ($Dias != null) {
            $inicioId = mysql_query("SELECT `idtempo` FROM `ebspma_paad_ebspma`.`req_material_tempo` WHERE `inicio`='$inicio'");
            $inicioRow = mysql_fetch_row($inicioId)or die(mysql_error());
            $inicio = $inicioRow[0];
            if ($inicio != null) {
                $salaId = mysql_query("SELECT `idsala` FROM `ebspma_paad_ebspma`.`req_material_sala` WHERE `sala` = '$sala'");
                $salaRow = mysql_fetch_row($salaId)or die(mysql_error());
                $sala = $salaRow[0];
                if ($sala != null) {
                    $fimId = mysql_query("SELECT `idtempo` FROM `ebspma_paad_ebspma`.`req_material_tempo` WHERE `fim`= '$fim'");
                    $fimRow = mysql_fetch_row($fimId)or die(mysql_error());
                    if ($fim != null) {
                        $checkIfOcupado = mysql_query("SELECT COUNT(id_dia) FROM `ebspma_paad_ebspma`. `sala_ocupacao` WHERE id_dia = '$Dias' AND id_sala= '$sala' AND id_tempo = '$inicio'");
                        $checkResult = mysql_fetch_row($checkIfOcupado) or die($checkIfOcupado . "<br/><br/>" . mysql_error());
                        $checkResultado = $checkResult[0];
                        if ($checkResultado > 0) {
                            $response["error"] = 2;
                            $response["error_msg"] = "Hora marcada no ano";
                            echo json_encode($response);
                        } else {
                            $checkIfReservado = mysql_query("SELECT COUNT(*) AS total FROM `ebspma_paad_ebspma`.`req_material_reserva` 
                            WHERE `ebspma_paad_ebspma`.`req_material_reserva`.`idsala` = '$sala'
                            AND (((`req_material_reserva`.`idtempoInicio` BETWEEN '$inicio' AND '$fim') AND (`req_material_reserva`.`idTempoFim` BETWEEN '$inicio' AND '$fim'))
                            OR (`req_material_reserva`.`idtempoInicio` <= '$inicio' AND `req_material_reserva`.`idTempoFim` >= '$fim'))
                            AND `req_material_reserva`.`data` = '$newDate'");
                            $checkReserva = mysql_fetch_row($checkIfReservado) or die($checkIfReservado . "<br/><br/>" . mysql_error());
                            $checkReservado = $checkReserva[0];
                            if ($checkReservado > 0) {
                                $response["error"] = 2;
                                $response["error_msg"] = "Oops! Sala reservada";
                                echo json_encode($response);
                            } else {
                                $response["success"] = 1;
                                $response["message"] = "Sala disponível.";
                                echo json_encode($response);
                            }
                        }
                    }
                }
            }
        }
    }

And  have this error in my android

Error parsing data org.json.JSONException: End of input at character 0 of

org.json.JSONException: No value for message

 

And my android is calling this json

private static final String KEY_MESSAGE = "message";
    private static final String KEY_MESSAGE_ERROR = "error_msg";     
	JSONObject salasCheck = userFunctions.reqSalasCheck(sala, inicio, fim, dataReserva);
            try {
                String res = salasCheck.getString(KEY_SUCCESS);
                Log.d("Mensagem", res);
                String error = salasCheck.getString(KEY_ERROR);
                Log.d("Mensagem", error);
                if (Integer.parseInt(res) == 1) {
                    String messageOK = salasCheck.getString(KEY_MESSAGE);

So why do i have this error in my php??

 

Link to comment
https://forums.phpfreaks.com/topic/296776-jsonexception-no-value-for-message/
Share on other sites

Hi

 

I don't get what's wrong in this code...everything is so strange.

I'm passing the variables to php from this code

@SuppressLint("SimpleDateFormat")
    public JSONObject reqSalasCheck(String sala, String inicio, String fim, Date dataReserva) {
        // Parametros a passar para php
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        String dataFinal = String.valueOf(dataReserva);
        String reqSalasCheck_tag = "reqSalasCheck";
        params.add(new BasicNameValuePair("tag", reqSalasCheck_tag));
        params.add(new BasicNameValuePair("sala", sala));
        params.add(new BasicNameValuePair("inicio", inicio));
        params.add(new BasicNameValuePair("fim", fim));
        params.add(new BasicNameValuePair("dataFinal", dataFinal));
        JSONObject json = jsonParser.getJSONFromUrl(loginURL, params);
        return json;
    }

and the debuger gives me this error

 

Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.apache.http.message.BasicNameValuePair.toString()

 

in every variable 

  • 2 years later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.