Jump to content

[SOLVED] Text Returned From DB Gets Cutoff When Placed In A Text Field


angelopc

Recommended Posts

I know this is easy...or at least I hope it is. I tried to find this problem already posted and couldn't, however I'm sure I'm not the first. I have a string that contains an apostrophe or a quotation mark, stored in a DB. I can retrieve the data, and display it properly (for editing) in a textarea, but when I try to put the string in a text field, it get's cut off right before the questionable character.

 

For example:

$string_in_database = "John's car."

 

-displays correctly here <textarea><?php print $string_in_database ?></textarea> and displays this - John's car.

 

-gets cutoff here <input type='text' value=''<?php print $string_in_database ?>' /> and displays this -  John

 

I've tried adding slashes and stripping slashes and I just can't figure out what I need to do. Please let me know if this is unclear to anyone. I appreciate your help.

You'll ned to enclose the value in a differant type of quote to the one thats in the string. So your example, try:

 

<input type = "text" value="<?php echo $string_in_database; ?>" />

 

Its because when the browser reads the HTML it finds the quote that got echoed by the php and thinks thats the terminating quote.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.