pinacoladaxb Posted June 20, 2008 Share Posted June 20, 2008 Here's some code I have for a form: <form> <INPUT TYPE="hidden" NAME="song" VALUE="<? echo $thissong; ?>"> <input type="submit" value="Submit"> </form> The problem is when $thissong has the character " in it because all of the characters including it and after that are ignored. Let's say $thissong = a"b. Here's what the source code would look like for that line: <INPUT TYPE="hidden" NAME="song" VALUE="a"b"> ...so the "b is ignored. Is there a way of preventing this? Link to comment https://forums.phpfreaks.com/topic/111189-using-the-character-in-html-forms-doesnt-work/ Share on other sites More sharing options...
hitman6003 Posted June 21, 2008 Share Posted June 21, 2008 use single quotes value='a"b' Link to comment https://forums.phpfreaks.com/topic/111189-using-the-character-in-html-forms-doesnt-work/#findComment-570682 Share on other sites More sharing options...
Mattyspatty Posted June 21, 2008 Share Posted June 21, 2008 also consider using this function http://uk.php.net/manual/en/function.htmlspecialchars.php Link to comment https://forums.phpfreaks.com/topic/111189-using-the-character-in-html-forms-doesnt-work/#findComment-570684 Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 Use addslashes() on the stuff you're putting into the value attribute. Link to comment https://forums.phpfreaks.com/topic/111189-using-the-character-in-html-forms-doesnt-work/#findComment-570685 Share on other sites More sharing options...
pinacoladaxb Posted June 21, 2008 Author Share Posted June 21, 2008 If I use single quotes, then what if the variable contains single quotes? If I add slashes, then the " will still be there, right? But the htmlspecialchars function worked perfectly! Thanks!!! Link to comment https://forums.phpfreaks.com/topic/111189-using-the-character-in-html-forms-doesnt-work/#findComment-570687 Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 You add slashes to escape the quotes. =/ Link to comment https://forums.phpfreaks.com/topic/111189-using-the-character-in-html-forms-doesnt-work/#findComment-570688 Share on other sites More sharing options...
PFMaBiSmAd Posted June 21, 2008 Share Posted June 21, 2008 The \ to escape characters don't mean anything to a browser. The htmlspecialchars or even better htmlentities is needed so that the special characters that a browser operates on can appear in data. Link to comment https://forums.phpfreaks.com/topic/111189-using-the-character-in-html-forms-doesnt-work/#findComment-570698 Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 Yeah, I realized that after trying it. D: I wasn't paying attention, lol. I thought he said when he echo'd it out he got an error. Then I re-read it. xD Link to comment https://forums.phpfreaks.com/topic/111189-using-the-character-in-html-forms-doesnt-work/#findComment-570701 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.