If you've ever worked with databases on your website, it is highly possible that you've come across this display issue before. What I am talking about is the white question mark in black diamond display error.
Before talking about what causes it and how to get rid of it, let me show you an example from an earlier stage of this site:
As you can see from the above image, some of the characters within the context of the web page are not displayed as they should. Two characters that are not rendered correctly in this example are the single quote (') and double quote (").
Single quotes and double quotes are heavily used in the coding of a web page such as in HTML, PHP and MySQL and therefore if you don't set them properly, the browser will get confused and will not display them correctly. At the time of writing this post, I checked it with four major browsers and while Chrome(12), Firefox(4) and Safari(5) displayed question mark in diamonds, Internet Explorer(8) displayed a small rectangle.
What causes "question marks in diamonds" display error?
In this specific example, it was the encoding type of the database that caused this error. Although I created the tables of the database in UTF-8 character encoding format, the quotes didn't display correctly. The problem was that, when I established a database connection to fetch the posts, I didn't specify the encoding format where I should.
How to solve "question marks in diamonds" display error?
To solve this small but annoying issue, you need to specify the encoding of the database connection using the function below:
Do not forget to replace $database_connection_variable with the one that you defined. Just a quick example:
$link = mysql_connect('db_host', 'db_user', 'db_pass');
Also, replace host, username, password and database name fields with yours. That's it. Refresh your page and you will see that the question marks in diamonds will have gone. I am not sure if the database encoding is the only reason for this display error but if I find another one I will post it here.
I hope you will find this mini tutorial useful, and please let me know if you know of another solution to this error.
Thanks for reading, please share this post if you found it useful. If you have any questions or comments about this post please use the comment form below.