0

I'm taking values from MySQL(PHPMyAdmin) to PHP and after that, I send them to an echo for taking those values on Ionic. I don't know why but when I add a specific value (Bio field from MySQL) inside the array and execute the .php file thows me a white screen.

Here is my code:

json-tecnico.php

<?php

require_once('connect.php');

$consulta = "SELECT
                idTecnico,
                nombre,
                apellido,
                cedula,
                genero,
                telefono,
                usuario,
                correo,
                ubicacion,
                bio,
                rate,
                catg.descripcion Categoria_Descripcion,
                subcat.descripcion Subcategoria_Descripcion
            FROM
                tecnico AS tec

            INNER JOIN categoria AS catg
            ON
                tec.categoria = catg.idCategoria
            INNER JOIN subcategoria AS subcat
            ON
                subcat.idCategoria = catg.idCategoria AND subcat.idSubcategoria = tec.subcategoria
            WHERE categoria = '".$_GET['categoria']."'";

    if(isset($_GET['subcategoria'])){
        $consulta = $consulta . " AND subcategoria = '".$_GET['subcategoria']."';";
    }

    $resultado = mysqli_query($conexion, $consulta);


        while($columna = mysqli_fetch_assoc($resultado)){
            $data[] = array(
                'id' => $columna['idTecnico'],
                'nombre' => $columna['nombre'],
                'apellido' => $columna['apellido'],
                'cedula' => $columna['cedula'],
                'genero' => $columna['genero'],
                'usuario' => $columna['usuario'],
                'ubicacion' => $columna['ubicacion'],
                'bio' => $columna['bio'],
                'rate' => $columna['rate'],
                'subcategoria' => $columna['Subcategoria_Descripcion']
            );
        }


    if(!empty($data)){
        echo json_encode($data);
    }

    else{
        $data[] = array(
            'success' => 'No se encontro usuarios con el criterio de busqueda dado',
            'workers' => false
        );
        echo json_encode($data);
    }

      mysqli_close($conexion); ?>

The white screen shows when I put the '007' value on $_GET['subcategoria'] and when I put the line 'bio' => $columna['bio'].

On MySQL, bio is varchar(500). Why is this happening?

A photo of the "tecnico" table on PHPmyAdmin

Saral
  • 1,087
  • 1
  • 8
  • 18
  • 3
    White screen... ? Check your browser dev tools network tab and if its a 500 error, then your php is cratering with a fatal error. Check your server logs for the problem. – IncredibleHat Jun 21 '18 at 02:37
  • 1
    You also are open to SQL injections. You should parameterize the query. – user3783243 Jun 21 '18 at 02:40
  • 1
    check your server log and also try echo $consulta; – User123456 Jun 21 '18 at 02:40
  • Add `ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);` to the top of your script. This will force any `mysqli_` errors to generate an Exception that you can see on the browser and other errors will also be visible on your browser. – RiggsFolly Jun 21 '18 at 03:09
  • > Network tab says Status: 200: OK
    > My server log says nothing about it
    > Also, `ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);` does not work.
    – Kevin Hernandez Avelino Jun 21 '18 at 05:16
  • How could adding error report settings NOT work?? :D – IncredibleHat Jun 21 '18 at 13:59

1 Answers1

0

Well, I already dig into the problem, just was an Encoding error. Using utf8_encode() on all the String variables solved my problem.

You can use this if you're getting encoding problems:

I got the Answer from here!


    function utf8ize($d) {
        if (is_array($d)) {
            foreach ($d as $k => $v) {
                $d[$k] = utf8ize($v);
            }
        } elseif (is_string ($d)) {
            return utf8_encode($d);
        }
        return $d;
    }

and after that:


    echo json_encode(utf8ize($data));