PDA

View Full Version : special characters not being saved to database correctly



james438
09-23-2017, 06:50 PM
I recently updated the php language on my website to 5.6.27. After doing so Special Characters no longer display correctly on my website. I am not sure if this has to do with my php.ini file.

My MySQL summary column in my article table is collated as utf8_general_ci

When I submit an endash to the database it looks like the following:

‚€“

Here is the code I am using:


<?php
include 'include/dbconnect.php';
include "$root/".'include/user.php';
$query="UPDATE article SET summary='X–X' WHERE ID='300'";
mysqli_query($conn,$query) or die ("Couldn't execute query.");
?>

The include files are only for database usernames and passwords.

When I go to phpmyadmin to look at how the endash is encoded it looks like ‚€“. When I display it on the website it looks like the endash should. When I try to edit the page and and submit the page to the database the encoded endash is then further encoded to ‚€“. Articles created before my php was updated display special characters as diamonds with a question mark in the middle: �

See the following page: http://www.animeviews.com/article.php?ID=262

Any ideas on how I can store special characters in my database as special characters again? Other examples of characters that are no longer stored in the database correctly include non breaking space, or the accented e in clientŤle, etc.

james438
09-24-2017, 12:35 AM
Fixed:


<?php
include 'include/dbconnect.php';
mysqli_query ($conn,"set character_set_results='utf8'");
mysqli_query ($conn,"set character_set_client='utf8'");
mysqli_query ($conn,"set collation_connection='utf8_general_ci'");
include "$root/".'include/user.php';
$query="UPDATE article SET summary='X–X' WHERE ID='300'";
mysqli_query($conn,$query) or die ("Couldn't execute query.");
?>

https://stackoverflow.com/questions/15892610/getting-special-characters-out-of-a-mysql-database-with-php