0

I want users to be able to post an icon/symbol (in example: ❤) in a form in HTML. After getting back the input in PHP, the symbol still exists. Where it goes wrong is when I put in into the database, then it converts into some weird symbols. I know it is not a problem in the database, since I am able to input the icons into the database using a Minecraft Plugin. There I added basically
?useUnicode=true&characterEncoding=UTF-8 to the URI and it worked. How is this possible to do using PHP? I use the following code for the connection: $conn = new mysqli($servername, $username, $password, $dbname);

Thanks!

1 Answers1

0

You can use:

mysqli_set_charset($conn,"utf8");

function.

It's in literally first google result for

mysqli character set

phrase.

matiit
  • 7,969
  • 5
  • 41
  • 65
  • At the moment I have the following, which does not work: – Bram van Dartel Oct 18 '16 at 13:03
  • `// Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } else { mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn); mysql_set_charset('utf8', $conn); }` – Bram van Dartel Oct 18 '16 at 13:03
  • Found the problem. Had `mysqli_set_charset("utf8",$conn);` instead of first `$conn`. Thanks! – Bram van Dartel Oct 18 '16 at 13:05