0

I'm not able to display ñ on a web I'm using to learn to code.

entry on mysql

mysql database has latin1_spanish_ci collation. I've tried setting collation to utf-8, using decode(utf-8), setting the page charset to charset=ISO-8859-1, but nothing seems to work.

This is the php code

index.php

<!DOCTYPE html>
<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <title>
            Bitácora
        </title>
    </head>
<body>
    <?php require_once('db_conn.php');?>
    <?php require_once('script.php');?>
    <?php if($_COOKIE['username'] === NULL){
        header("Location: login.php");
        } else {
        //
        }
    ?>
    <div>
    <p>Estás logueado como " <?php echo ucwords(strtolower($row['nombre'])) . " " . ucwords(strtolower($row['apellido'])); ?>"</p>
    </div>
    <form action="inserta.php" id="formaLog" name="formaLog" method="POST">
    <textarea style="overflow:auto;resize:none" rows="4" cols="80" id="log" name="log" required></textarea>
    <input type="submit" name="envia" value="Enviar" id="envia" />
    </form>
    <br />  
<?php require_once('menu.php'); ?>

</body>
</html>

script.php

<?php
require_once('db_conn.php');


$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

    if( isset($_COOKIE['user_id']) ){
    //  mysqli_set_charset($dbc,"utf8");
    // Look up the username and password in the database
        $username = $_COOKIE['username'];
        $id = $_COOKIE['user_id'];
        $query = "SELECT id, username, nombre, apellido FROM usuarios WHERE username = '$username'";
        $data = mysqli_query($dbc, $query);


        if (mysqli_num_rows($data) == 1) {
    // The log-in is OK so set the user ID and username cookies, and redirect to the home page
        $row = mysqli_fetch_array($data);

        }
    }

?>
esquizoide
  • 15
  • 4
  • what is output you see exactly instead? – Seyfi Jul 26 '16 at 20:50
  • table posts : ñññ table usuarios: Ricardo Carre�o I'm going to check if there is any difference in configuration – esquizoide Jul 27 '16 at 16:18
  • 1
    The problem was with the following function ucwords(strtolower($row['apellido'])), it doesn't support ñ quite right. – esquizoide Jul 28 '16 at 22:21
  • I recommend you wirte an answer to your own question and accept your own answer if this is the answer, so every one with your problem that redirects here would benefit. – Seyfi Jul 29 '16 at 14:10
  • This is the answer, i don't know how to post it, but it's taken from the the answer that shows in the duplicated message. Working with Unicode in PHP is easy as long as you realize that most of the string functions don't work with Unicode, and some might mangle strings completely. PHP considers "characters" to be 1 byte long. Sometimes this is okay (for example, explode() only looks for a byte sequence and uses it as a separator -- so it doesn't matter what actual characters you look for). PHP has no idea that your text has multi-byte characters that are found with Unicode. – esquizoide Jul 30 '16 at 18:38

0 Answers0