0

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!

2 Answers 2

1

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>"
Sign up to request clarification or add additional context in comments.

2 Comments

Bingo! :D it worked! also xdazz would you mind explaining the difference circumstances htmlspecialchar or htmlentities should use or both deliveres the same protection?
You could use either of them. The difference is what gets encoded, the special char or the entity.
1

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).

3 Comments

Nope Stegrex! still I dont get the rest with htmlentities()
As xdazz mentioned yes quotes are missing and your suggestions worked! Thank you!
@AmwAmw Try doing echo $row['route']; and check the source of the page in a browser (not just what you see on the page, basically hit Ctrl+U). Also not that you need the single quotes to wrap around the value right after "value=" as xdazz noted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.