PHP & MySQL - Problems with UTF-8 encode -


i have form input accept utf-8 characters:

<form method="post" action="faz-personagem.php" accept-charset="utf-8">   <div class="row">     <label for="nome">nome</label>     <input type="text" name="nome">   </div>   ...   <button type="submit">enviar</button> </form> 

and script send data database:

<?php  header("content-type: text/html;charset=utf-8");  $conexao = mysql_connect('localhost', 'root', 'pass'); mysql_select_db('pan-tactics');  $nome   = $_post['nome'];  $nome = utf8_encode($nome);  $sql = "insert personagens values"; $sql .= "('$nome')";  $resultado = mysql_query($sql);  echo 'personagem criado com sucesso.';  mysql_close($conexao);  ?> 

i have specified in creation of database collation utf8_unicode_ci , yet wrong special characters:

when send string "joão" field "nome" of database

what can fix it?

keep in mind collation not same charset. need set database , table in utf-8 encoding. can done running sql command (only need done once).

alter database databasename character set utf8 collate utf8_unicode_ci; alter table tablename convert character set utf8 collate utf8_unicode_ci; 

furthermore, should set mysql_* connection uft-8. code should placed directly after connecting database.

mysql_set_charset("utf8"); 

i see set php header utf-8 well, that's good.

keep in mind usage of mysql_* functions deprecated , no longer maintained; should switch pdo or mysqli security reasons.

if neither of these steps helped you, may need save document utf-8 w/o bom, can done in notepad++ format -> convert uft-8 w/o bom.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -