Jump to content

Json Error End of input character 0 of


gmc1103

Recommended Posts

Hi

 

I have a strange error in this code, the fisrt function works fine but the second one gives me "End of input character 0 of"

    <?php

    setlocale(LC_ALL, "pt_BR", "pt_BR.iso-8859-1", "pt_BR.utf-8", "portuguese");
    if (isset($_POST['tag']) && $_POST['tag'] != '') {

        // tag escolhida
        $tag = filter_input(INPUT_POST, 'tag');
        // inclui db handler
        require_once 'include/DB_Functions.php';
        $db = new DB_Functions();
        \mysql_query("SET NAMES 'utf8'");
        $response = array("tag" => $tag, "success" => 0, "error" => 0);
        if ($tag == 'login') {
            $utilizador = filter_input(INPUT_POST, 'utilizador');
            $password = filter_input(INPUT_POST, 'password');
            $user = $db->getUserByNomeEPassword($utilizador, $password);
            if ($user != false) {
                $response["success"] = 1;
                $response["user"]["nome"] = $user["nome"];
                $response["user"]["utilizador"] = $user["utilizador"];
                $response["user"]["idutilizador"] = $user["idutilizador"];
                $response["user"]["tipoutilizador_idtipoutilizador"] = $user["tipoutilizador_idtipoutilizador"];
                echo json_encode($response);
            } else {
                $response["error"] = 0;
                $response["error_msg"] = "Utilizador ou password errados!";
                echo json_encode($response);
            }
        }

        //Verificado
        if ($tag == 'reqSalasCheck') {
            $idUser = filter_input(INPUT_POST, 'idUser');
            $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"] = 0;
                                $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"] = 0;
                                    $response["error_msg"] = "Oops! Sala reservada";
                                    echo json_encode($response);
                                } else {
                                    $response["success"] = 1;
                                    $response["message"] = "Sala disponível.";
                                    echo json_encode($response);
                                }
                            }
                        }
                    }
                }
            }
        }

        if ($tag == 'checkEquipReserva') {
            $idUser = filter_input(INPUT_POST, 'idUser');
            $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"] = 0;
                                $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"] = 0;
                                    $response["error_msg"] = "Oops! Sala reservada";
                                    echo json_encode($response);
                                } else {
                                    $response["success"] = 1;
                                    $response["message"] = "Sala disponível.";
                                    echo json_encode($response);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

The first function works fine "reqSalasCheck" the second gives me tha error and they are equal....why?

 

Regards

Link to comment
Share on other sites

It appears you are outputting multiple json responses. This is error is most likely the response from your client as it unable to parse the json output from your script.

 

You need to change your code so one one json response is returned, preferably at the end of your script.

Link to comment
Share on other sites

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.