Amw Amw
Amw Amw

Reputation: 43

getting SQL database infor to a dynamically created text box

Hi I have a text box dynamically created to get a value from a database. The specific line in the code is as follows and it works fine;

<input name='routename'  class='colr' type='text' id='routename' size='20' maxlength='40' value=".$row['route']."></td>

How ever my database has a value 'colombo/ srilanka' and when the result is loaded to the text box it captured only 'colombo/' and 'srilanka' is missing. In other words text after the space is not loaded to the textbox. Can someone help me with a workaround?

Thanks for looking!

Upvotes: 0

Views: 91

Answers (2)

xdazz
xdazz

Reputation: 160843

You missed the quotes of the value, and don't forget using htmlspecialcharor htmlentities.

"<input name='routename'  class='colr' type='text' id='routename' size='20' maxlength='40' value='".htmlspecialchar($row['route'])."'></td>"

Upvotes: 1

Stegrex
Stegrex

Reputation: 4024

Try htmlentities():

echo "<input name='routename'  class='colr' type='text' id='routename' size='20' maxlength='40' value='".htmlentities($row['route'])."' /></td>";

When you echo anything from PHP into HTML, you should always wrap the string with htmlentities to make sure the outputted string is safe for HTML to display (without inadvertently writing markup to the page instead).

Upvotes: 1

Related Questions