0

I'm creating a test application and keeping the name of the person who is taking it on a table, along with the answers. The problem lies when I enter the following characters

á é í ó ú ñ

I've tried some methods (like iconv function) but still not working.

//A sample of the code

require('../connect_db.php');
setlocale(LC_ALL,"es_ES");
mysql_query("SET NAMES 'utf8'");

$sql  =  "SELECT *
          FROM database.test";
$result     = mysql_query($sql) or die (mysql_error());
$row        = mysql_fetch_array($result);
$name      = utf8decode($row[1]);

echo mb_detect_encoding($name); //Just to test
echo $name;

The result:

UTF-8 G�mez


Edit: The problem is not on the database. I've manually entered names with these characters with no problem, so it must be the code.

JackYag
  • 1
  • 1
  • 2
    **Stop** using deprecated mysql_* API. Use mysqli_* or PDO – Jens May 18 '17 at 17:29
  • Possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Dymen1 May 18 '17 at 17:36

1 Answers1

0

SOLVED

There was no need to run the first utf8decode() when assigning values to $name

Instead I just called the function at the echo

JackYag
  • 1
  • 1