How to correctly reference charset = utf8

1

I have my coding in my php code in the PDO connection, it works correctly, but when you insert the data into MySQL, you can see it; (Ñ) Send them in lowercase CASTAñEDA example, in my form in most of the fields, I have what is $ strtoupper but I put all in lowercase and all converted to uppercase minus the tildes that I mention, I know that it is the case, some people say that they do not go with an accent but for example I put a character like this -> (Á, Ó) and similarly converts them into the base in (á, ó) example (Song) I do not know what my error is I'm investigating about $ mb_strtoupper but I really need an example in coding.

This is my code, in MySQL create the table with utf8_general_ci

<?php

$errores = NULL;
$enviado = FALSE;

if (isset($_POST['submit'])) {
$nombre =(empty(trim($_POST['nombre'])))  ? NULL :  strtoupper($_POST['nombre']);
$apellidopaterno = (empty(trim($_POST['apellidopaterno']))) ? NULL :  strtoupper($_POST['apellidopaterno']);
$apellidomaterno = (empty(trim($_POST['apellidomaterno']))) ? NULL :  strtoupper($_POST['apellidomaterno']);
$telefono = (empty(trim($_POST['telefono']))) ? NULL :   $_POST['telefono'];
$correo = (empty(trim($_POST['correo']))) ? NULL : $_POST['correo'];
$mensaje = (empty(trim($_POST['mensaje']))) ? NULL :  strtoupper($_POST['mensaje']);

 try{
                                  //codificación
    $conexion = new PDO ('mysql:host=localhost;dbname=pruebas;charset=utf8', 'root', '');

}catch (PDOException $e) {
    echo    "Error:" . $e->getMessage();
}

try{

    if (!$nombre){
        $errores .= 'Por favor ingresa tu nombre <br />';
    }

    if (!$apellidopaterno){
        $errores .= 'Por favor ingresa tu apellido paterno <br />';
    }

    if (!$apellidomaterno){
        $errores .= 'Por favor ingresa tu apellido materno <br />';
    }

    if (!$telefono){
        $errores .= 'Por favor ingresa tu teléfono <br />';
    }

    if (!$correo){
        $errores .= 'Por favor ingresa tu correo <br />';
    }

    if (!$mensaje){
        $errores .= 'Por favor ingresa un mensaje <br />';
    }

    if (!$errores){

        $statement = $conexion->prepare("INSERT INTO usuario(nombre,apellidopaterno,apellidomaterno,telefono,correo,mensaje)VALUES( :nombre, :apellidopaterno,:apellidomaterno, :telefono, :correo, :mensaje)");
        $statement->bindParam(':nombre', $nombre);
        $statement->bindParam(':apellidopaterno', $apellidopaterno);
        $statement->bindParam(':apellidomaterno', $apellidomaterno);
        $statement->bindParam(':telefono', $telefono);
        $statement->bindParam(':correo', $correo);
        $statement->bindParam(':mensaje', $mensaje);
        $conexion->beginTransaction();
        $statement->execute();
        $conexion->commit();
        $enviado=TRUE;
    }

}catch(Exception $e) {
    $conexion->rollback();
    echo "Error: 0" . $e->getMessage();
}


}

require 'index.view.php';



?>
    
asked by carlos 28.08.2018 в 19:47
source

1 answer

2

Use mb_strtoupper() instead of strtoupper() , since this method takes coding into account

$str = mb_strtolower($_POST['nombre'], 'UTF-8');

Even if you have already configured the encoding, you can omit it, as specified in the documentation

  

The encoding parameter is the character encoding. If it is omitted, the value of the internal character encoding will be used.

More information from mb_strtoupper: link

    
answered by 28.08.2018 / 19:58
source