Forum Moderators: coopster

Message Too Old, No Replies

Weird quote problem

Assigning value to text feild. Blank if value has quotes

         

nfs2

12:35 am on Apr 9, 2006 (gmt 0)

10+ Year Member



So i pull some text from mysql ( it was placed there using mysql_real_escape_string), and i pull it using stripslashes. I then assign it to fill a text feild.

It works great unless it has quotes. For example

<input type="text" value="<?php echo stripslashes($row['text_feild'])?>" />

Anything in quotes dissapears, which is weird because stripslashes($row['text_feild']) works fine every where else (outside of a text feild.

Any ideas?

nfs2

1:30 am on Apr 9, 2006 (gmt 0)

10+ Year Member



Ok some more info; It happens no matter how the data is inserted or called from the database. It happens whenever i have to populate a text field with a value that has double quotes.

Birdman

2:19 am on Apr 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try htmlspecialchars [php.net].

<input type="text" value="<?php echo htmlspecialchars(stripslashes($row['text_feild']))?>" />

There is a second (optional) argument dealing with quotes. Check the manual link above.

DrDoc

2:46 am on Apr 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



... and the reason for this being ...

Say that the string is

"foo"
, the input field will now look something like this:
<input ... value=[b]"[red]"[/b]foo"[/red]">
with the bold portion being treated by the browser as the value, when the red portion is what you want.

nfs2

4:04 am on Apr 9, 2006 (gmt 0)

10+ Year Member



Cool, now i know why it happens and how to avoid it.

Thanks to both of you!