tags:

views:

47

answers:

3

I have a question about inserting values into an input field from my MYSQL DB.

First I have a form to save data from an inputfield to the database. An extra script filters diacrits Á=>Á to html code. So Állo will be saved like Állo

When I insert the data from the DB to a 'div' it shows Állo. When I insert the data into a input field it shows Állo

What am I doing wrong

I use JQUERY to save data to the DB with the $.post method without pagerefresh. I also get the data from the DB with JQUERY $.post method without pagerefresh.

Hope somebody can help.

A: 

You are inserting HTML into the div, but setting the DOM value property of the input directly.

An HTML entity is converted to what it represents in HTML, but the value property expects text so doesn't attribute any special meaning to the &.

You should be storing the actual data in the database, not an HTML view of it. Conversion to HTML should be handled on the way out of the server side program (in the View if you are using an MVC design pattern).

David Dorward
Ok, tnx, but when I insert the Á from the DB into the input field my browser shows the '?' or an other symbol and not the Á. I don't want to change my browser settings because viewers of my page must see Á and not the '?'
Megapool020
A: 

Have a script that reverses what the encoding script does and call it when you output to the form fields.

RandyMorris
A: 

you really shouldn't save htmlentities to your database. you should instead save Állo and use htmlspecialshars($my_value_from_db); if its needed (this is php don't know whats runnung on your server, but there are similar functions for perl or other languages). if you can't change the saving process or correct al old entries, you could use html_entity_decode($bla) for values that are shown in input-fields (this is php again)

oezi
This did the trick. I looked up for the encoding and I needed to utf8_encode my string I gave back.Tnx!!!!!
Megapool020