Solved

Display special characters from database

Posted on 2009-04-09
6
681 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
6 Comments
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 336 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 168 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 336 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

685 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