Show unicode texts (other languages) in my table made in php using ajax and jquery

2

Hello, I have made a table in php in which I will show several contents and by which one can search for these contents in the table. But a question arises when I try to write letters in other languages, it shows me as ? with interrogations, an example creating a field in another language:

The code of my php my table will work with ajax and jquery, in my table in phpmyadmin the value is created but if it is a unicode character it introduces it with interrogations. The important part where I will show the table:

<div class="registros" id="agrega-registros"></div>
    <center>
        <ul class="pagination" id="pagination"></ul>
    </center>
    <!-- MODAL PARA EL REGISTRO DE PRODUCTOS-->
    <div class="modal fade" id="registra-producto" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
              <h4 class="modal-title" id="myModalLabel"><b>Registra o Edita un Producto</b></h4>
            </div>
            <form id="formulario" class="formulario" onsubmit="return agregaRegistro();">
            <div class="modal-body">
                <table border="0" width="100%">
                     <tr>
                        <td colspan="2"><input type="text" required="required" readonly="readonly" id="id-prod" name="id-prod" readonly="readonly" style="visibility:hidden; height:5px;"/></td>
                    </tr>
                     <tr>
                        <td width="150">Proceso: </td>
                        <td><input type="text" required="required" readonly="readonly" id="pro" name="pro"/></td>
                    </tr>
                    <tr>
                        <td>Nombre: </td>
                        <td><input type="text" required="required" name="nombre" id="nombre" maxlength="100"/></td>
                    </tr>
                   <tr>
                        <td>Tipo: </td>
                        <td>
                        <input type="text" required="required" name="tipo" id="tipo" maxlength="100"/>
                    </tr>
                    <tr>
                        <td>URL: </td>
                        <td><input type="text" required="required" name="precio-uni" id="precio-uni"/></td>
                    </tr>
                    <tr>
                        <td>Numero: </td>
                        <td><input type="number"  required="required" name="precio-dis" id="precio-dis"/></td>
                    </tr>
                        <td colspan="2">
                            <div id="mensaje"></div>
                        </td>
                    </tr>
                </table>
            </div>

            <div class="modal-footer">
                <input type="submit" value="Registrar" class="btn btn-success" id="reg"/>
                <input type="submit" value="Editar" class="btn btn-warning"  id="edi"/>
            </div>
            </form>
          </div>
        </div>
      </div>

The php to enter the products:

<?php
include('conexion.php');

$database_connection=  database_connect();
$id = $_POST['id-prod'];
$proceso = $_POST['pro'];
$nombre = $_POST['nombre'];
$tipo = $_POST['tipo'];
$precio_uni = $_POST['precio-uni'];
$precio_dis = $_POST['precio-dis'];
$fecha = date('Y-m-d');
//VERIFICAMOS EL PROCESO

switch($proceso){
    case 'Registro':
        $database_connection->query("INSERT INTO productos (nomb_prod, tipo_prod, precio_unit, precio_dist, fecha_reg)VALUES('$nombre','$tipo','$precio_uni','$precio_dis', '$fecha')");
    break;

    case 'Edicion':
        $database_connection->query("UPDATE productos SET nomb_prod = '$nombre', tipo_prod = '$tipo', precio_unit = '$precio_uni', precio_dist = '$precio_dis' WHERE id_prod = '$id'");
    break;
}


//ACTUALIZAMOS LOS REGISTROS Y LOS OBTENEMOS

$registro = $database_connection->query("SELECT * FROM productos ORDER BY id_prod ASC");

//CREAMOS NUESTRA VISTA Y LA DEVOLVEMOS AL AJAX

echo '<table class="table table-striped table-condensed table-hover">
            <tr>
                <th width="0px">Nombre</th>
                            <th width="0px">Descripcion</th>
        <th width="50">Opciones</th>
            </tr>';
$registro = $database_connection-> query("SELECT * FROM productos")->fetchAll();
    foreach ($registro as $registro2){
        echo '<tr>
                <td>'.$registro2['nomb_prod'].'</td>
                <td><a href="https://'.$registro2['precio_unit'].'">'.$registro2['tipo_prod'].'</a></td>
                                <td><a href="javascript:editarProducto('.$registro2['id_prod'].');" class="glyphicon glyphicon-edit"></a> <a href="javascript:eliminarProducto('.$registro2['id_prod'].');" class="glyphicon glyphicon-remove-circle"></a></td>
                </tr>';
    }
echo '</table>';
?>      

The page:

http://hzforo.byethost24.com/?i=1

Anyone can enter the page and add something. But the problem is if I write something in unicode in the table of my database if you enter it in unicode character it will see in this way the field ???????? there is some way to solve it.

    
asked by vivo vivo 17.03.2017 в 20:17
source

1 answer

0

good day. emm, the theme of the character set is somewhat complicated, all your files and your data should have the same coding (character set) so they can be seen properly, I will try to give you some tips.

  • Your files should be stored in an encoding that supports global characters, the current standard is utf-8, your code editor should store your files in that encoding, and all the files you use should match that encoding , otherwise in php for example a file_get_contents might not show the ñ for example.PD: it also influences that there are characters before the first

  • The character set of your database, tables, cells should be in the same encoding, the standad is utf8_general_ci although there are other more complete encodings that are also utf8.

  • Although there are still pages formatted in html4, it is appropriate to use the html5 headers, this could be noticed on your page, you are using html4 and html5 tags combined, so that you work correctly utf8 in html you would have to modify the following to Start of your code:

    (Everything has a space after the first

  • answered by 18.03.2017 / 08:55
    source