Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Display special characters from database

Posted on 2009-04-09
6
Medium Priority
?
687 Views
Last Modified: 2014-05-11
Hello,
I have a simple php page that allows a user to update database data.  The data is then displayed on a webpage (VERY simple content admin).

Occasionaly, special characters like bullets, and trademarks are used in these updates.

IDEALLY I would like to be able to just copy and paste text with these characters in the php form that updates the database, but when I do this, I get "unknown character icons" on the display page.

Using special character codes would be okay (not optimum), but the problem I am running into is when I use the codes ("•" for example), they show up fine on the display webpage the first time, but if I go back and use the php form to make a change, the character codes show up as the characters they represent in the form field and when I update the database, the "unknown character icons" are displayed on the page again, thus creating a situation where I have to convert the characters to their code counterparts everytime I edit the page.

How can I get the display page to display the special characters, or, short of that, retain the character codes when I edit the data in my php form?

Thanks in adavance.
0
Comment
Question by:tmbdesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 1344 total points
ID: 24112489
This can be very tricky, one approach to learn the character encoding is to go to View->Encoding and to try different character encoding schemas to see which one displays the characters properly, then add a meta tag identifying this schema, e.g.:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

PHP also offers you character encoding conversion functions such as http://us2.php.net/iconv that allow you to convert from one encoding schema to another.
0
 

Assisted Solution

by:kevintynfron
kevintynfron earned 672 total points
ID: 24121127
I'm not sure from your description exactly what you're seeing, but I had problems with this kind of thing as well.

I had my database character set as UTF-8 and the web page using UTF-8 as shown above, but I was still having problems editing it as the characters weren't showing up properly in the edit box.

In the end, I used the htmlspecialchars function to populate the text box in my PHP.
<input value="<?php echo htmlspecialchars($row_member_details['surname']); ?>" type="text" name="member_surname" id="member_surname" />

Open in new window

0
 
LVL 19

Assisted Solution

by:LordOfPorts
LordOfPorts earned 1344 total points
ID: 24123301
One other important fact is which character encoding your database uses, when you connect to you MySQL database try issuing the following command before you query the database:
mysql_query("SET NAMES 'utf8'");

Open in new window

0
 

Author Comment

by:tmbdesign
ID: 24354818
Hey Everybody,
I am so sorry to have abandoned this question.  I got way busy with other things and couldn't find time to follow through with the suggestions.

I still hope to get back to this project at some point, but in the mean time, I agree with the split.

Thanks.
0
 
LVL 2

Expert Comment

by:ref-IT
ID: 40057266
Hello Boys,

I'm aware that this post has long since been closed, but I'd like to mention that LordOfPorts's solution of changing MySQL Database's characters set using

mysql_query("SET NAMES 'utf8'");

before querying the database actually worked for me.

Thanks a lot and God Bless.

ref-IT
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question