Difficulty with Encoding

0

Good,

I have a PHP file with encoding UTF-8. And the text with accents in the HTML is how it should be, but when I go to the database, there are strange characters.

Database Encoding

Database data

Database data seen in the php file

include("connection.php");
<?php
   include("connection.php");

   echo "<div class='narrow-block wrapper'>
<h2>Inscrições (Federados)</h2>
<table id='table2'>
   	$result2 = mysqli_query($con,"SELECT * FROM registofederados");
	while($row = mysqli_fetch_array($result2)){
		echo "<tr>";
			echo "<td>" . $row['dorsal'] . "</td>";
			echo "<td>" . $row['nome'] . "</td>";
			echo "<td>" . $row['bi'] . "</td>";
			echo "<td>" . $row['dataNasc'] . "</td>";
			echo "<td>" . $row['n_federado'] . "</td>";
			echo "<td>" . $row['email'] . "</td>";
			echo "<td>" . $row['telemovel'] . "</td>";
			echo "<td>" . $row['morada'] . "</td>";
			echo "<td>" . $row['local_dorsal'] . "</td>";
			echo "<td>" . $row['pagamento'] . "</td>";
			echo "<td>" . $row['equipa'] . "</td>";
			echo "<td>" . $row['categoria'] . "km </td>";
			if($row['almoco'] == 1)
				echo "<td>Sim</td>";
			else
				echo "<td>Não</td>";
			if($row['pago'] == 1)
				echo "<td>Sim</td>";
			else
				echo "<td>Não</td>";
		echo "</tr>";
	}
   	</table>
  </div>";
mysqli_close($con);
?>
    
asked by anonymous 19.06.2015 / 16:21

1 answer

1

Run the following command before executing the query:

if( function_exists('mysql_set_charset') ) { 
    mysql_set_charset('utf8', $con); 
} else { 
    mysql_query("SET NAMES 'utf8'", $con); 
}

You can also change the encoding of your database to:

utf8_general_ci
    
19.06.2015 / 16:47