In my database I have data for example a code such as this: <script type="text/javascript">alert('Xss done');</script>
I get the data from database and I need to populate them in input field. My user then can edit the code. I confuse whether I need to escape the javascript code in my input field because I understand you only need to escape it if you display it with <label>, or <p> element etc etc.
But right now I'm getting alert box with that code. Should I escape it?? If yes then how can I properly escape it because I use this code htmlspecialchars($user_input, ENT_QUOTES) and the javascript code in the input field successfully turn into this <script type="text/javascript">alert('Xss done');</script> but I'm still getting the alert box??
Please help me and thank you.