Store javascript script in database

Hi,

I am trying to store following open web analytics javascript code in database but not getting success.

I tried with utf8_encode and str_rot13 but no result.It shows blank in update query.

<?php

$Con_2 = new mysqli("localhost","root","password","owa");

echo"<br>".$owa_javascript = "

<!-- Start Open Web Analytics Tracker -->
<script type='text/javascript'>
//<![CDATA[
var owa_baseUrl = 'http://localhost/owa/';
var owa_cmds = owa_cmds || [];
owa_cmds.push(['setSiteId', 'F747E44E-B526-41EC-802E-8F7E15575AD8']);
owa_cmds.push(['trackPageView']);
owa_cmds.push(['trackClicks']);
owa_cmds.push(['trackDomStream']);

(function() {
var _owa = document.createElement('script'); _owa.type = 'text/javascript'; _owa.async = true;
owa_baseUrl = ('https:' == document.location.protocol ? window.owa_baseSecUrl || owa_baseUrl.replace(/http:/, 'https:') : owa_baseUrl );
_owa.src = owa_baseUrl + 'modules/base/js/owa.tracker-combined-min.js';
var _owa_s = document.getElementsByTagName('script')[0]; _owa_s.parentNode.insertBefore(_owa, _owa_s);
}());
//]]>
</script>
<!-- End Open Web Analytics Code -->

";

//$owa_javascript = utf8_encode($owa_javascript);

//$owa_javascript = str_rot13($owa_javascript);

echo"<br>".$sql = " UPDATE tbl_table SET owa_siteid = 'F747E44E-B526-41EC-802E-8F7E15575AD8', owa_javascript='$owa_javascript' WHERE id='48' ";
mysqli_query($Con_2,$sql);


//UPDATE tbl_table SET owa_siteid = 'F747E44E-B526-41EC-802E-8F7E15575AD8', owa_javascript=' ' WHERE id='1'


?>

Any Idea?

-Thanks

Technically it is just a string you are inserting. It looks as if you need to escape it. What error are you receiving?

You will want to review:
http://us1.php.net/manual/en/mysqli.real-escape-string.php

If you use prepare/bind instead of query for the database call then you will not need to escape the script.

Hi,

I am not getting values in variable in query $owa_javascript

Following is the result of query with empty value for owa_javascript

UPDATE tbl_table SET owa_siteid = 'F747E44E-B526-41EC-802E-8F7E15575AD8', owa_javascript=' ' WHERE id='1' 

Any Idea?

-Thanks

Hi,

Could you help in writing my php code using php mysqli_stmt::bind_param as per below url

http://jp.php.net/manual/en/mysqli-stmt.bind-param.php

-Thanks

Try this example I have explained it with my code:

BTW, the code should read
element_html=tr1.innerHTML;
var str1=“id=rowid_1”; //string to replace
var str2="id=row_id_1 onclick=alert(“hello”); //replace str1 with this
element_html=element_html.replace(str1, str2);
write element_html to oracle database.

Hi Robert,

As per felgall problem will be solved using prepare/bind statement.

I have created post for same , I think it will solve the problem.

http://www.sitepoint.com/forums/showthread.php?1203618-mysqli-prepare-statement-not-working

Any idea?

Hi,

This problem is solved using prepare/bind.

-Thanks