Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP/MySql to javascript not working

There is something wrong with the way I am printing MySQL and the javascript is not executing it. Here is an example.

square[1] = "asdfasdfadsf";

When I print "asdfasdfadsf" from my MySQL database, the javascript does not work. However, if I simply type "asdfasdfadsf" in the static HTML it executes fine. I have tried as many PHP functions and charset conversions as I can. Please Help!

like image 718
Matt Beighey Avatar asked Jan 27 '26 08:01

Matt Beighey


1 Answers

I suggest the json_encode PHP function. Apart from properly printing the string, it also escapes all dangerous characters.

square[1] = <?php echo json_encode($my_string); ?>;
like image 53
Matej Konecny Avatar answered Jan 28 '26 22:01

Matej Konecny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!