1. Yes, it is possible.
Javascript code is text only. Technically, there is no problem storing it in the database. Whether it is recommended or the best solution is another question.
2. Is it safe? Depends.
It depends completely on the use you intend to give to this code. Where it comes from, where it goes, and how it is used.
In the database, no Javascript execution environment. It’s safe. As said above, it’s just another string text. You will need to take precautions common to any other text content, notably the escape, avoiding vulnerabilities that are independent of the text being "Javascript code" or any other type of text.
Already in the applying, depends a lot, varying from one extreme to another: depending on the use can be dangerous or safe.
To analyze, you need to start by considering: How do you intend to use this code? Who can supply the bank with this code?
The danger of using user-generated Javascript code is that a malicious user can easily program an HTTP request to be made, triggering other functions of your application (for example, simulate the effect of a click on "Like", send the authentication cookie to a remote server, et cetera).
Why don’t you use files
.js
even?– J. Bruni
Solved, treating the string this way: $messaging_escape = str_replace("'", "'", $message);
– Odair
@Odair Use
mysql_real_escape_string
instead ofstr_replace
http://www.php.net/manual/en/function.mysql-real-escape-string.php– Emerson Rocha
Thanks @Emersonrochaluiz I will change here, thank you so much for your help!
– Odair
I usually put in the BD in Base64 Encode format the language codes...
– user4569